Skip to content

Commit 00ef370

Browse files
Merge branch '4.4' into 5.2
* 4.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 2c85cb8 + 9979144 commit 00ef370

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
@@ -812,7 +812,7 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
812812
$len = 0;
813813
}
814814

815-
if (false !== strpos($message, "@anonymous\0")) {
815+
if (str_contains($message, "@anonymous\0")) {
816816
$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) {
817817
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
818818
}, $message);
@@ -1113,7 +1113,7 @@ private function findAlternatives(string $name, iterable $collection): array
11131113
}
11141114

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

11241124
foreach ($collection as $item) {
11251125
$lev = levenshtein($name, $item);
1126-
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
1126+
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
11271127
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
11281128
}
11291129
}

Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public function getSynopsis(bool $short = false)
604604
*/
605605
public function addUsage(string $usage)
606606
{
607-
if (0 !== strpos($usage, $this->name)) {
607+
if (!str_starts_with($usage, $this->name)) {
608608
$usage = sprintf('%s %s', $this->name, $usage);
609609
}
610610

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);
@@ -254,7 +254,7 @@ public function getFirstArgument()
254254
$isOption = false;
255255
foreach ($this->tokens as $i => $token) {
256256
if ($token && '-' === $token[0]) {
257-
if (false !== strpos($token, '=') || !isset($this->tokens[$i + 1])) {
257+
if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
258258
continue;
259259
}
260260

@@ -296,8 +296,8 @@ public function hasParameterOption($values, bool $onlyParams = false)
296296
// Options with values:
297297
// For long options, test for '--option=' at beginning
298298
// For short options, test for '-o' at beginning
299-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
300-
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
299+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
300+
if ($token === $value || '' !== $leading && str_starts_with($token, $leading)) {
301301
return true;
302302
}
303303
}
@@ -327,8 +327,8 @@ public function getParameterOption($values, $default = false, bool $onlyParams =
327327
// Options with values:
328328
// For long options, test for '--option=' at beginning
329329
// For short options, test for '-o' at beginning
330-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
331-
if ('' !== $leading && 0 === strpos($token, $leading)) {
330+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
331+
if ('' !== $leading && str_starts_with($token, $leading)) {
332332
return substr($token, \strlen($leading));
333333
}
334334
}

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
@@ -56,7 +56,7 @@ class InputOption
5656
*/
5757
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
5858
{
59-
if (0 === strpos($name, '--')) {
59+
if (str_starts_with($name, '--')) {
6060
$name = substr($name, 2);
6161
}
6262

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
@@ -19,7 +19,7 @@
1919
"php": ">=7.2.5",
2020
"symfony/polyfill-mbstring": "~1.0",
2121
"symfony/polyfill-php73": "^1.8",
22-
"symfony/polyfill-php80": "^1.15",
22+
"symfony/polyfill-php80": "^1.16",
2323
"symfony/service-contracts": "^1.1|^2",
2424
"symfony/string": "^5.1"
2525
},

0 commit comments

Comments
 (0)