Skip to content

Commit 276a57b

Browse files
Merge branch '4.4' into 5.2
* 4.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents b2d7f78 + d6e4f59 commit 276a57b

18 files changed

+29
-29
lines changed

Command/AbstractConfigCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function findExtension(string $name)
113113
}
114114
}
115115

116-
if ('Bundle' !== substr($name, -6)) {
116+
if (!str_ends_with($name, 'Bundle')) {
117117
$message = sprintf('No extensions with configuration available for "%s".', $name);
118118
} else {
119119
$message = sprintf('No extension with alias "%s" is enabled.', $name);

Command/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
$realBuildDir = $kernel->getContainer()->hasParameter('kernel.build_dir') ? $kernel->getContainer()->getParameter('kernel.build_dir') : $realCacheDir;
8484
// the old cache dir name must not be longer than the real one to avoid exceeding
8585
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
86-
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
86+
$oldCacheDir = substr($realCacheDir, 0, -1).(str_ends_with($realCacheDir, '~') ? '+' : '~');
8787
$fs->remove($oldCacheDir);
8888

8989
if (!is_writable($realCacheDir)) {

Command/ContainerDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
237237
$serviceIds = $builder->getServiceIds();
238238
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
239239
foreach ($serviceIds as $serviceId) {
240-
if (!$showHidden && 0 === strpos($serviceId, '.')) {
240+
if (!$showHidden && str_starts_with($serviceId, '.')) {
241241
continue;
242242
}
243243
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
@@ -262,7 +262,7 @@ public function filterToServiceTypes(string $serviceId): bool
262262
}
263263

264264
// if the id has a \, assume it is a class
265-
if (false !== strpos($serviceId, '\\')) {
265+
if (str_contains($serviceId, '\\')) {
266266
return true;
267267
}
268268

Command/ContainerLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function getContainerBuilder(): ContainerBuilder
113113

114114
$skippedIds = [];
115115
foreach ($container->getServiceIds() as $serviceId) {
116-
if (0 === strpos($serviceId, '.errored.')) {
116+
if (str_starts_with($serviceId, '.errored.')) {
117117
$skippedIds[$serviceId] = true;
118118
}
119119
}

Command/DebugAutowiringCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080

8181
if ($search = $input->getArgument('search')) {
8282
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($search) {
83-
return false !== stripos(str_replace('\\', '', $serviceId), $search) && 0 !== strpos($serviceId, '.');
83+
return false !== stripos(str_replace('\\', '', $serviceId), $search) && !str_starts_with($serviceId, '.');
8484
});
8585

8686
if (empty($serviceIds)) {
@@ -104,7 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
104104
foreach ($serviceIds as $serviceId) {
105105
$text = [];
106106
$resolvedServiceId = $serviceId;
107-
if (0 !== strpos($serviceId, $previousId)) {
107+
if (!str_starts_with($serviceId, $previousId)) {
108108
$text[] = '';
109109
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
110110
if (isset($hasAlias[$serviceId])) {

Command/XliffLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct()
3737
};
3838

3939
$isReadableProvider = function ($fileOrDirectory, $default) {
40-
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
40+
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
4141
};
4242

4343
parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);

Command/YamlLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct()
3636
};
3737

3838
$isReadableProvider = function ($fileOrDirectory, $default) {
39-
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
39+
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
4040
};
4141

4242
parent::__construct(null, $directoryIteratorProvider, $isReadableProvider);

Console/Descriptor/JsonDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private function getCallableData($callable): array
312312
$data['name'] = $callable[1];
313313
$data['class'] = \get_class($callable[0]);
314314
} else {
315-
if (0 !== strpos($callable[1], 'parent::')) {
315+
if (!str_starts_with($callable[1], 'parent::')) {
316316
$data['name'] = $callable[1];
317317
$data['class'] = $callable[0];
318318
$data['static'] = true;
@@ -330,7 +330,7 @@ private function getCallableData($callable): array
330330
if (\is_string($callable)) {
331331
$data['type'] = 'function';
332332

333-
if (false === strpos($callable, '::')) {
333+
if (!str_contains($callable, '::')) {
334334
$data['name'] = $callable;
335335
} else {
336336
$callableParts = explode('::', $callable);
@@ -347,7 +347,7 @@ private function getCallableData($callable): array
347347
$data['type'] = 'closure';
348348

349349
$r = new \ReflectionFunction($callable);
350-
if (false !== strpos($r->name, '{closure}')) {
350+
if (str_contains($r->name, '{closure}')) {
351351
return $data;
352352
}
353353
$data['name'] = $r->name;

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ protected function describeCallable($callable, array $options = [])
328328
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
329329
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
330330
} else {
331-
if (0 !== strpos($callable[1], 'parent::')) {
331+
if (!str_starts_with($callable[1], 'parent::')) {
332332
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
333333
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
334334
$string .= "\n- Static: yes";
@@ -346,7 +346,7 @@ protected function describeCallable($callable, array $options = [])
346346
if (\is_string($callable)) {
347347
$string .= "\n- Type: `function`";
348348

349-
if (false === strpos($callable, '::')) {
349+
if (!str_contains($callable, '::')) {
350350
$string .= "\n".sprintf('- Name: `%s`', $callable);
351351
} else {
352352
$callableParts = explode('::', $callable);
@@ -363,7 +363,7 @@ protected function describeCallable($callable, array $options = [])
363363
$string .= "\n- Type: `closure`";
364364

365365
$r = new \ReflectionFunction($callable);
366-
if (false !== strpos($r->name, '{closure}')) {
366+
if (str_contains($r->name, '{closure}')) {
367367
return $this->write($string."\n");
368368
}
369369
$string .= "\n".sprintf('- Name: `%s`', $r->name);

Console/Descriptor/TextDescriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private function formatControllerLink($controller, string $anchorText, callable
548548
$r = new \ReflectionMethod($controller, '__invoke');
549549
} elseif (!\is_string($controller)) {
550550
return $anchorText;
551-
} elseif (false !== strpos($controller, '::')) {
551+
} elseif (str_contains($controller, '::')) {
552552
$r = new \ReflectionMethod($controller);
553553
} else {
554554
$r = new \ReflectionFunction($controller);
@@ -601,7 +601,7 @@ private function formatCallable($callable): string
601601

602602
if ($callable instanceof \Closure) {
603603
$r = new \ReflectionFunction($callable);
604-
if (false !== strpos($r->name, '{closure}')) {
604+
if (str_contains($r->name, '{closure}')) {
605605
return 'Closure()';
606606
}
607607
if ($class = $r->getClosureScopeClass()) {

0 commit comments

Comments
 (0)