Skip to content

Commit a0efb26

Browse files
committed
minor #44506 Leverage str_starts_with(), str_ends_with() and str_contains() (fancyweb)
This PR was merged into the 6.1 branch. Discussion ---------- Leverage str_starts_with(), str_ends_with() and str_contains() | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Continuation of the previous ones. Let's see if the CI is green first. Commits ------- bbe96c7d72 Leverage str_starts_with(), str_ends_with() and str_contains()
2 parents 02f16e3 + 0574d40 commit a0efb26

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
@@ -237,7 +237,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array
237237
$lastError = preg_last_error();
238238

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

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

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

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)