Skip to content

Commit 4a8f884

Browse files
Merge branch '5.2' into 5.3
* 5.2: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents c9f211b + 276a57b commit 4a8f884

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
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8484
$realBuildDir = $kernel->getContainer()->hasParameter('kernel.build_dir') ? $kernel->getContainer()->getParameter('kernel.build_dir') : $realCacheDir;
8585
// the old cache dir name must not be longer than the real one to avoid exceeding
8686
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
87-
$oldCacheDir = substr($realCacheDir, 0, -1).('~' === substr($realCacheDir, -1) ? '+' : '~');
87+
$oldCacheDir = substr($realCacheDir, 0, -1).(str_ends_with($realCacheDir, '~') ? '+' : '~');
8888
$fs->remove($oldCacheDir);
8989

9090
if (!is_writable($realCacheDir)) {

Command/ContainerDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
239239
$serviceIds = $builder->getServiceIds();
240240
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
241241
foreach ($serviceIds as $serviceId) {
242-
if (!$showHidden && 0 === strpos($serviceId, '.')) {
242+
if (!$showHidden && str_starts_with($serviceId, '.')) {
243243
continue;
244244
}
245245
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
@@ -264,7 +264,7 @@ public function filterToServiceTypes(string $serviceId): bool
264264
}
265265

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

Command/ContainerLintCommand.php

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

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

Command/DebugAutowiringCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
if ($search = $input->getArgument('search')) {
8484
$searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search);
8585
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
86-
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && 0 !== strpos($serviceId, '.');
86+
return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && !str_starts_with($serviceId, '.');
8787
});
8888

8989
if (empty($serviceIds)) {
@@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107107
foreach ($serviceIds as $serviceId) {
108108
$text = [];
109109
$resolvedServiceId = $serviceId;
110-
if (0 !== strpos($serviceId, $previousId)) {
110+
if (!str_starts_with($serviceId, $previousId)) {
111111
$text[] = '';
112112
if ('' !== $description = Descriptor::getClassDescription($serviceId, $resolvedServiceId)) {
113113
if (isset($hasAlias[$serviceId])) {

Command/XliffLintCommand.php

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

4040
$isReadableProvider = function ($fileOrDirectory, $default) {
41-
return 0 === strpos($fileOrDirectory, '@') || $default($fileOrDirectory);
41+
return str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);
4242
};
4343

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

Command/YamlLintCommand.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);

Console/Descriptor/JsonDescriptor.php

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

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

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

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ protected function describeCallable($callable, array $options = [])
337337
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
338338
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
339339
} else {
340-
if (0 !== strpos($callable[1], 'parent::')) {
340+
if (!str_starts_with($callable[1], 'parent::')) {
341341
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
342342
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
343343
$string .= "\n- Static: yes";
@@ -355,7 +355,7 @@ protected function describeCallable($callable, array $options = [])
355355
if (\is_string($callable)) {
356356
$string .= "\n- Type: `function`";
357357

358-
if (false === strpos($callable, '::')) {
358+
if (!str_contains($callable, '::')) {
359359
$string .= "\n".sprintf('- Name: `%s`', $callable);
360360
} else {
361361
$callableParts = explode('::', $callable);
@@ -372,7 +372,7 @@ protected function describeCallable($callable, array $options = [])
372372
$string .= "\n- Type: `closure`";
373373

374374
$r = new \ReflectionFunction($callable);
375-
if (false !== strpos($r->name, '{closure}')) {
375+
if (str_contains($r->name, '{closure}')) {
376376
return $this->write($string."\n");
377377
}
378378
$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
@@ -556,7 +556,7 @@ private function formatControllerLink($controller, string $anchorText, callable
556556
$r = new \ReflectionMethod($controller, '__invoke');
557557
} elseif (!\is_string($controller)) {
558558
return $anchorText;
559-
} elseif (false !== strpos($controller, '::')) {
559+
} elseif (str_contains($controller, '::')) {
560560
$r = new \ReflectionMethod($controller);
561561
} else {
562562
$r = new \ReflectionFunction($controller);
@@ -609,7 +609,7 @@ private function formatCallable($callable): string
609609

610610
if ($callable instanceof \Closure) {
611611
$r = new \ReflectionFunction($callable);
612-
if (false !== strpos($r->name, '{closure}')) {
612+
if (str_contains($r->name, '{closure}')) {
613613
return 'Closure()';
614614
}
615615
if ($class = $r->getClosureScopeClass()) {

Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ private function getCallableDocument($callable): \DOMDocument
505505
$callableXML->setAttribute('name', $callable[1]);
506506
$callableXML->setAttribute('class', \get_class($callable[0]));
507507
} else {
508-
if (0 !== strpos($callable[1], 'parent::')) {
508+
if (!str_starts_with($callable[1], 'parent::')) {
509509
$callableXML->setAttribute('name', $callable[1]);
510510
$callableXML->setAttribute('class', $callable[0]);
511511
$callableXML->setAttribute('static', 'true');
@@ -523,7 +523,7 @@ private function getCallableDocument($callable): \DOMDocument
523523
if (\is_string($callable)) {
524524
$callableXML->setAttribute('type', 'function');
525525

526-
if (false === strpos($callable, '::')) {
526+
if (!str_contains($callable, '::')) {
527527
$callableXML->setAttribute('name', $callable);
528528
} else {
529529
$callableParts = explode('::', $callable);
@@ -540,7 +540,7 @@ private function getCallableDocument($callable): \DOMDocument
540540
$callableXML->setAttribute('type', 'closure');
541541

542542
$r = new \ReflectionFunction($callable);
543-
if (false !== strpos($r->name, '{closure}')) {
543+
if (str_contains($r->name, '{closure}')) {
544544
return $dom;
545545
}
546546
$callableXML->setAttribute('name', $r->name);

Controller/RedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function urlRedirectAction(Request $request, string $path, bool $permanen
129129
}
130130

131131
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
132-
if (false === strpos($path, '?')) {
132+
if (!str_contains($path, '?')) {
133133
$qs = '?'.$qs;
134134
} else {
135135
$qs = '&'.$qs;

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function process(ContainerBuilder $container)
111111
continue;
112112
}
113113

114-
if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
114+
if (str_contains($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
115115
$candidates[] = $definedTag;
116116
}
117117
}

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
13181318
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
13191319
'cache_vary' => [
13201320
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
1321-
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
1321+
return str_starts_with($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
13221322
}, $scannedDirectories),
13231323
],
13241324
]

Routing/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function load($resource, string $type = null)
8282
continue;
8383
}
8484

85-
if (false !== strpos($controller, '::')) {
85+
if (str_contains($controller, '::')) {
8686
continue;
8787
}
8888

Secrets/DotenvVault.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function reveal(string $name): ?string
5454
{
5555
$this->lastMessage = null;
5656
$this->validateName($name);
57-
$v = \is_string($_SERVER[$name] ?? null) && 0 !== strpos($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);
57+
$v = \is_string($_SERVER[$name] ?? null) && !str_starts_with($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);
5858

5959
if (null === $v) {
6060
$this->lastMessage = sprintf('Secret "%s" not found in "%s".', $name, $this->getPrettyPath($this->dotenvFile));

Tests/Functional/CachePoolsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public function testRedisCachePools()
3535
try {
3636
$this->doTestCachePools(['root_config' => 'redis_config.yml', 'environment' => 'redis_cache'], RedisAdapter::class);
3737
} catch (\PHPUnit\Framework\Error\Warning $e) {
38-
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
38+
if (!str_starts_with($e->getMessage(), 'unable to connect to')) {
3939
throw $e;
4040
}
4141
$this->markTestSkipped($e->getMessage());
4242
} catch (InvalidArgumentException $e) {
43-
if (0 !== strpos($e->getMessage(), 'Redis connection ')) {
43+
if (!str_starts_with($e->getMessage(), 'Redis connection ')) {
4444
throw $e;
4545
}
4646
$this->markTestSkipped($e->getMessage());
@@ -58,7 +58,7 @@ public function testRedisCustomCachePools()
5858
try {
5959
$this->doTestCachePools(['root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'], RedisAdapter::class);
6060
} catch (\PHPUnit\Framework\Error\Warning $e) {
61-
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
61+
if (!str_starts_with($e->getMessage(), 'unable to connect to')) {
6262
throw $e;
6363
}
6464
$this->markTestSkipped($e->getMessage());

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/http-foundation": "^5.3",
2828
"symfony/http-kernel": "^5.3",
2929
"symfony/polyfill-mbstring": "~1.0",
30-
"symfony/polyfill-php80": "^1.15",
30+
"symfony/polyfill-php80": "^1.16",
3131
"symfony/filesystem": "^4.4|^5.0",
3232
"symfony/finder": "^4.4|^5.0",
3333
"symfony/routing": "^5.3"

0 commit comments

Comments
 (0)