Skip to content

Commit 9979144

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent e72a900 commit 9979144

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $outpu
877877
$len = 0;
878878
}
879879

880-
if (false !== strpos($message, "@anonymous\0")) {
880+
if (str_contains($message, "@anonymous\0")) {
881881
$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) {
882882
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
883883
}, $message);
@@ -1155,7 +1155,7 @@ private function findAlternatives(string $name, iterable $collection): array
11551155
}
11561156

11571157
$lev = levenshtein($subname, $parts[$i]);
1158-
if ($lev <= \strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
1158+
if ($lev <= \strlen($subname) / 3 || '' !== $subname && str_contains($parts[$i], $subname)) {
11591159
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
11601160
} elseif ($exists) {
11611161
$alternatives[$collectionName] += $threshold;
@@ -1165,7 +1165,7 @@ private function findAlternatives(string $name, iterable $collection): array
11651165

11661166
foreach ($collection as $item) {
11671167
$lev = levenshtein($name, $item);
1168-
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
1168+
if ($lev <= \strlen($name) / 3 || str_contains($item, $name)) {
11691169
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
11701170
}
11711171
}

Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public function getSynopsis($short = false)
613613
*/
614614
public function addUsage($usage)
615615
{
616-
if (0 !== strpos($usage, $this->name)) {
616+
if (!str_starts_with($usage, $this->name)) {
617617
$usage = sprintf('%s %s', $this->name, $usage);
618618
}
619619

Formatter/OutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function formatAndWrap(string $message, int $width)
180180

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

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

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
}
@@ -377,7 +377,7 @@ function ($match) use ($ret) {
377377
private function mostRecentlyEnteredValue(string $entered): string
378378
{
379379
// Determine the most recent value that the user entered
380-
if (false === strpos($entered, ',')) {
380+
if (!str_contains($entered, ',')) {
381381
return $entered;
382382
}
383383

Input/ArgvInput.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function parse()
7575
$this->parseArgument($token);
7676
} elseif ($parseOptions && '--' == $token) {
7777
$parseOptions = false;
78-
} elseif ($parseOptions && 0 === strpos($token, '--')) {
78+
} elseif ($parseOptions && str_starts_with($token, '--')) {
7979
$this->parseLongOption($token);
8080
} elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
8181
$this->parseShortOption($token);
@@ -243,7 +243,7 @@ public function getFirstArgument()
243243
$isOption = false;
244244
foreach ($this->tokens as $i => $token) {
245245
if ($token && '-' === $token[0]) {
246-
if (false !== strpos($token, '=') || !isset($this->tokens[$i + 1])) {
246+
if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
247247
continue;
248248
}
249249

@@ -285,8 +285,8 @@ public function hasParameterOption($values, $onlyParams = false)
285285
// Options with values:
286286
// For long options, test for '--option=' at beginning
287287
// For short options, test for '-o' at beginning
288-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
289-
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
288+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
289+
if ($token === $value || '' !== $leading && str_starts_with($token, $leading)) {
290290
return true;
291291
}
292292
}
@@ -316,8 +316,8 @@ public function getParameterOption($values, $default = false, $onlyParams = fals
316316
// Options with values:
317317
// For long options, test for '--option=' at beginning
318318
// For short options, test for '-o' at beginning
319-
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
320-
if ('' !== $leading && 0 === strpos($token, $leading)) {
319+
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
320+
if ('' !== $leading && str_starts_with($token, $leading)) {
321321
return substr($token, \strlen($leading));
322322
}
323323
}

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

0 commit comments

Comments
 (0)