Skip to content

Commit 0574d40

Browse files
committed
Leverage str_starts_with(), str_ends_with() and str_contains()
1 parent 331f9ea commit 0574d40

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

AbstractString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function split(string $delimiter, int $limit = null, int $flags = null):
458458
$lastError = preg_last_error();
459459

460460
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
461-
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
461+
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
462462
throw new RuntimeException('Splitting failed with '.$k.'.');
463463
}
464464
}

AbstractUnicodeString.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array
235235
$lastError = preg_last_error();
236236

237237
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
238-
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
238+
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
239239
throw new RuntimeException('Matching failed with '.$k.'.');
240240
}
241241
}
@@ -327,7 +327,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static
327327
$lastError = preg_last_error();
328328

329329
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
330-
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
330+
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
331331
throw new RuntimeException('Matching failed with '.$k.'.');
332332
}
333333
}
@@ -465,7 +465,7 @@ public function width(bool $ignoreAnsiDecoration = true): int
465465
$width = 0;
466466
$s = str_replace(["\x00", "\x05", "\x07"], '', $this->string);
467467

468-
if (false !== strpos($s, "\r")) {
468+
if (str_contains($s, "\r")) {
469469
$s = str_replace(["\r\n", "\r"], "\n", $s);
470470
}
471471

ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array
240240
$lastError = preg_last_error();
241241

242242
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
243-
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
243+
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
244244
throw new RuntimeException('Matching failed with '.$k.'.');
245245
}
246246
}
@@ -312,7 +312,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static
312312
$lastError = preg_last_error();
313313

314314
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
315-
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
315+
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
316316
throw new RuntimeException('Matching failed with '.$k.'.');
317317
}
318318
}

Inflector/EnglishInflector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public function singularize(string $plural): array
384384
if ($j === $suffixLength) {
385385
// Is there any character preceding the suffix in the plural string?
386386
if ($j < $pluralLength) {
387-
$nextIsVocal = false !== strpos('aeiou', $lowerPluralRev[$j]);
387+
$nextIsVocal = str_contains('aeiou', $lowerPluralRev[$j]);
388388

389389
if (!$map[2] && $nextIsVocal) {
390390
// suffix may not succeed a vocal but next char is one
@@ -464,7 +464,7 @@ public function pluralize(string $singular): array
464464
if ($j === $suffixLength) {
465465
// Is there any character preceding the suffix in the plural string?
466466
if ($j < $singularLength) {
467-
$nextIsVocal = false !== strpos('aeiou', $lowerSingularRev[$j]);
467+
$nextIsVocal = str_contains('aeiou', $lowerSingularRev[$j]);
468468

469469
if (!$map[2] && $nextIsVocal) {
470470
// suffix may not succeed a vocal but next char is one

LazyString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static function getPrettyName(callable $callback): string
127127
} elseif ($callback instanceof \Closure) {
128128
$r = new \ReflectionFunction($callback);
129129

130-
if (false !== strpos($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
130+
if (str_contains($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
131131
return $r->name;
132132
}
133133

Slugger/AsciiSlugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function slug(string $string, string $separator = '-', string $locale = n
9696
$locale = $locale ?? $this->defaultLocale;
9797

9898
$transliterator = [];
99-
if ($locale && ('de' === $locale || 0 === strpos($locale, 'de_'))) {
99+
if ($locale && ('de' === $locale || str_starts_with($locale, 'de_'))) {
100100
// Use the shortcut for German in UnicodeString::ascii() if possible (faster and no requirement on intl)
101101
$transliterator = ['de-ASCII'];
102102
} elseif (\function_exists('transliterator_transliterate') && $locale) {

0 commit comments

Comments
 (0)