Skip to content

Commit 300db7f

Browse files
Merge branch '5.2' into 5.3
* 5.2: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 9832efe + 00ef370 commit 300db7f

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
819819
$len = 0;
820820
}
821821

822-
if (false !== strpos($message, "@anonymous\0")) {
822+
if (str_contains($message, "@anonymous\0")) {
823823
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
824824
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
825825
}, $message);
@@ -1119,7 +1119,7 @@ private function findAlternatives(string $name, iterable $collection): array
11191119
}
11201120

11211121
$lev = levenshtein($subname, $parts[$i]);
1122-
if ($lev <= \strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
1122+
if ($lev <= \strlen($subname) / 3 || '' !== $subname && str_contains($parts[$i], $subname)) {
11231123
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
11241124
} elseif ($exists) {
11251125
$alternatives[$collectionName] += $threshold;
@@ -1129,7 +1129,7 @@ private function findAlternatives(string $name, iterable $collection): array
11291129

11301130
foreach ($collection as $item) {
11311131
$lev = levenshtein($name, $item);
1132-
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
1132+
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
11331133
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
11341134
}
11351135
}

Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public function getSynopsis(bool $short = false)
652652
*/
653653
public function addUsage(string $usage)
654654
{
655-
if (0 !== strpos($usage, $this->name)) {
655+
if (!str_starts_with($usage, $this->name)) {
656656
$usage = sprintf('%s %s', $this->name, $usage);
657657
}
658658

Formatter/OutputFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function escape(string $text)
5252
*/
5353
public static function escapeTrailingBackslash(string $text): string
5454
{
55-
if ('\\' === substr($text, -1)) {
55+
if (str_ends_with($text, '\\')) {
5656
$len = \strlen($text);
5757
$text = rtrim($text, '\\');
5858
$text = str_replace("\0", '', $text);
@@ -178,7 +178,7 @@ public function formatAndWrap(?string $message, int $width)
178178

179179
$output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength);
180180

181-
if (false !== strpos($output, "\0")) {
181+
if (str_contains($output, "\0")) {
182182
return strtr($output, ["\0" => '\\', '\\<' => '<']);
183183
}
184184

Helper/QuestionHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
311311
$matches = array_filter(
312312
$autocomplete($ret),
313313
function ($match) use ($ret) {
314-
return '' === $ret || 0 === strpos($match, $ret);
314+
return '' === $ret || str_starts_with($match, $ret);
315315
}
316316
);
317317
$numMatches = \count($matches);
@@ -348,7 +348,7 @@ function ($match) use ($ret) {
348348

349349
foreach ($autocomplete($ret) as $value) {
350350
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
351-
if (0 === strpos($value, $tempRet)) {
351+
if (str_starts_with($value, $tempRet)) {
352352
$matches[$numMatches++] = $value;
353353
}
354354
}
@@ -374,7 +374,7 @@ function ($match) use ($ret) {
374374
private function mostRecentlyEnteredValue(string $entered): string
375375
{
376376
// Determine the most recent value that the user entered
377-
if (false === strpos($entered, ',')) {
377+
if (!str_contains($entered, ',')) {
378378
return $entered;
379379
}
380380

Input/ArgvInput.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function parse()
7272
$this->parseArgument($token);
7373
} elseif ($parseOptions && '--' == $token) {
7474
$parseOptions = false;
75-
} elseif ($parseOptions && 0 === strpos($token, '--')) {
75+
} elseif ($parseOptions && str_starts_with($token, '--')) {
7676
$this->parseLongOption($token);
7777
} elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
7878
$this->parseShortOption($token);
@@ -264,7 +264,7 @@ public function getFirstArgument()
264264
$isOption = false;
265265
foreach ($this->tokens as $i => $token) {
266266
if ($token && '-' === $token[0]) {
267-
if (false !== strpos($token, '=') || !isset($this->tokens[$i + 1])) {
267+
if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
268268
continue;
269269
}
270270

@@ -306,8 +306,8 @@ public function hasParameterOption($values, bool $onlyParams = false)
306306
// Options with values:
307307
// For long options, test for '--option=' at beginning
308308
// For short options, test for '-o' at beginning
309-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
310-
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
309+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
310+
if ($token === $value || '' !== $leading && str_starts_with($token, $leading)) {
311311
return true;
312312
}
313313
}
@@ -337,8 +337,8 @@ public function getParameterOption($values, $default = false, bool $onlyParams =
337337
// Options with values:
338338
// For long options, test for '--option=' at beginning
339339
// For short options, test for '-o' at beginning
340-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
341-
if ('' !== $leading && 0 === strpos($token, $leading)) {
340+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
341+
if ('' !== $leading && str_starts_with($token, $leading)) {
342342
return substr($token, \strlen($leading));
343343
}
344344
}

Input/ArrayInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ protected function parse()
133133
if ('--' === $key) {
134134
return;
135135
}
136-
if (0 === strpos($key, '--')) {
136+
if (str_starts_with($key, '--')) {
137137
$this->addLongOption(substr($key, 2), $value);
138-
} elseif (0 === strpos($key, '-')) {
138+
} elseif (str_starts_with($key, '-')) {
139139
$this->addShortOption(substr($key, 1), $value);
140140
} else {
141141
$this->addArgument($key, $value);

Input/InputOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class InputOption
6161
*/
6262
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
6363
{
64-
if (0 === strpos($name, '--')) {
64+
if (str_starts_with($name, '--')) {
6565
$name = substr($name, 2);
6666
}
6767

Logger/ConsoleLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function hasErrored()
104104
*/
105105
private function interpolate(string $message, array $context): string
106106
{
107-
if (false === strpos($message, '{')) {
107+
if (!str_contains($message, '{')) {
108108
return $message;
109109
}
110110

Style/SymfonyStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private function autoPrependText(): void
447447
{
448448
$fetched = $this->bufferedOutput->fetch();
449449
//Prepend new line if last char isn't EOL:
450-
if ("\n" !== substr($fetched, -1)) {
450+
if (!str_ends_with($fetched, "\n")) {
451451
$this->newLine();
452452
}
453453
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/polyfill-mbstring": "~1.0",
2222
"symfony/polyfill-php73": "^1.8",
23-
"symfony/polyfill-php80": "^1.15",
23+
"symfony/polyfill-php80": "^1.16",
2424
"symfony/service-contracts": "^1.1|^2",
2525
"symfony/string": "^5.1"
2626
},

0 commit comments

Comments
 (0)