Skip to content

Commit d6e4f59

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent a91e9d4 commit d6e4f59

22 files changed

+36
-36
lines changed

Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected function getScript($request)
167167

168168
$requires = '';
169169
foreach (get_declared_classes() as $class) {
170-
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
170+
if (str_starts_with($class, 'ComposerAutoloaderInit')) {
171171
$r = new \ReflectionClass($class);
172172
$file = \dirname($r->getFileName(), 2).'/autoload.php';
173173
if (file_exists($file)) {

Command/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
142142
}
143143
$mount = implode(' ', $mount).'/';
144144

145-
if (0 === strpos($realCacheDir, $mount)) {
145+
if (str_starts_with($realCacheDir, $mount)) {
146146
$io->note('For better performances, you should move the cache and log directories to a non-shared folder of the VM.');
147147
$oldCacheDir = false;
148148
break;

Command/ContainerDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private function findServiceIdsContaining(ContainerBuilder $builder, string $nam
270270
$serviceIds = $builder->getServiceIds();
271271
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
272272
foreach ($serviceIds as $serviceId) {
273-
if (!$showHidden && 0 === strpos($serviceId, '.')) {
273+
if (!$showHidden && str_starts_with($serviceId, '.')) {
274274
continue;
275275
}
276276
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
@@ -295,7 +295,7 @@ public function filterToServiceTypes(string $serviceId): bool
295295
}
296296

297297
// if the id has a \, assume it is a class
298-
if (false !== strpos($serviceId, '\\')) {
298+
if (str_contains($serviceId, '\\')) {
299299
return true;
300300
}
301301

Command/ContainerLintCommand.php

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

105105
$skippedIds = [];
106106
foreach ($container->getServiceIds() as $serviceId) {
107-
if (0 === strpos($serviceId, '.errored.')) {
107+
if (str_starts_with($serviceId, '.errored.')) {
108108
$skippedIds[$serviceId] = true;
109109
}
110110
}

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
@@ -286,7 +286,7 @@ private function getCallableData($callable): array
286286
$data['name'] = $callable[1];
287287
$data['class'] = \get_class($callable[0]);
288288
} else {
289-
if (0 !== strpos($callable[1], 'parent::')) {
289+
if (!str_starts_with($callable[1], 'parent::')) {
290290
$data['name'] = $callable[1];
291291
$data['class'] = $callable[0];
292292
$data['static'] = true;
@@ -304,7 +304,7 @@ private function getCallableData($callable): array
304304
if (\is_string($callable)) {
305305
$data['type'] = 'function';
306306

307-
if (false === strpos($callable, '::')) {
307+
if (!str_contains($callable, '::')) {
308308
$data['name'] = $callable;
309309
} else {
310310
$callableParts = explode('::', $callable);
@@ -321,7 +321,7 @@ private function getCallableData($callable): array
321321
$data['type'] = 'closure';
322322

323323
$r = new \ReflectionFunction($callable);
324-
if (false !== strpos($r->name, '{closure}')) {
324+
if (str_contains($r->name, '{closure}')) {
325325
return $data;
326326
}
327327
$data['name'] = $r->name;

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ protected function describeCallable($callable, array $options = [])
300300
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
301301
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
302302
} else {
303-
if (0 !== strpos($callable[1], 'parent::')) {
303+
if (!str_starts_with($callable[1], 'parent::')) {
304304
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
305305
$string .= "\n".sprintf('- Class: `%s`', $callable[0]);
306306
$string .= "\n- Static: yes";
@@ -318,7 +318,7 @@ protected function describeCallable($callable, array $options = [])
318318
if (\is_string($callable)) {
319319
$string .= "\n- Type: `function`";
320320

321-
if (false === strpos($callable, '::')) {
321+
if (!str_contains($callable, '::')) {
322322
$string .= "\n".sprintf('- Name: `%s`', $callable);
323323
} else {
324324
$callableParts = explode('::', $callable);
@@ -335,7 +335,7 @@ protected function describeCallable($callable, array $options = [])
335335
$string .= "\n- Type: `closure`";
336336

337337
$r = new \ReflectionFunction($callable);
338-
if (false !== strpos($r->name, '{closure}')) {
338+
if (str_contains($r->name, '{closure}')) {
339339
return $this->write($string."\n");
340340
}
341341
$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
@@ -514,7 +514,7 @@ private function formatControllerLink($controller, string $anchorText): string
514514
$r = new \ReflectionMethod($controller, '__invoke');
515515
} elseif (!\is_string($controller)) {
516516
return $anchorText;
517-
} elseif (false !== strpos($controller, '::')) {
517+
} elseif (str_contains($controller, '::')) {
518518
$r = new \ReflectionMethod($controller);
519519
} else {
520520
$r = new \ReflectionFunction($controller);
@@ -547,7 +547,7 @@ private function formatCallable($callable): string
547547

548548
if ($callable instanceof \Closure) {
549549
$r = new \ReflectionFunction($callable);
550-
if (false !== strpos($r->name, '{closure}')) {
550+
if (str_contains($r->name, '{closure}')) {
551551
return 'Closure()';
552552
}
553553
if ($class = $r->getClosureScopeClass()) {

Console/Descriptor/XmlDescriptor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private function getCallableDocument($callable): \DOMDocument
469469
$callableXML->setAttribute('name', $callable[1]);
470470
$callableXML->setAttribute('class', \get_class($callable[0]));
471471
} else {
472-
if (0 !== strpos($callable[1], 'parent::')) {
472+
if (!str_starts_with($callable[1], 'parent::')) {
473473
$callableXML->setAttribute('name', $callable[1]);
474474
$callableXML->setAttribute('class', $callable[0]);
475475
$callableXML->setAttribute('static', 'true');
@@ -487,7 +487,7 @@ private function getCallableDocument($callable): \DOMDocument
487487
if (\is_string($callable)) {
488488
$callableXML->setAttribute('type', 'function');
489489

490-
if (false === strpos($callable, '::')) {
490+
if (!str_contains($callable, '::')) {
491491
$callableXML->setAttribute('name', $callable);
492492
} else {
493493
$callableParts = explode('::', $callable);
@@ -504,7 +504,7 @@ private function getCallableDocument($callable): \DOMDocument
504504
$callableXML->setAttribute('type', 'closure');
505505

506506
$r = new \ReflectionFunction($callable);
507-
if (false !== strpos($r->name, '{closure}')) {
507+
if (str_contains($r->name, '{closure}')) {
508508
return $dom;
509509
}
510510
$callableXML->setAttribute('name', $r->name);

Controller/ControllerNameParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function build($controller)
107107
$controllerName = $match[2];
108108
$actionName = $match[3];
109109
foreach ($this->kernel->getBundles() as $name => $bundle) {
110-
if (0 !== strpos($className, $bundle->getNamespace())) {
110+
if (!str_starts_with($className, $bundle->getNamespace())) {
111111
continue;
112112
}
113113

@@ -130,7 +130,7 @@ private function findAlternative(string $nonExistentBundleName): ?string
130130
$shortest = null;
131131
foreach ($bundleNames as $bundleName) {
132132
// if there's a partial match, return it immediately
133-
if (false !== strpos($bundleName, $nonExistentBundleName)) {
133+
if (str_contains($bundleName, $nonExistentBundleName)) {
134134
return $bundleName;
135135
}
136136

Controller/ControllerResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(ContainerInterface $container, $logger = null)
5151
*/
5252
protected function createController($controller)
5353
{
54-
if ($this->parser && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
54+
if ($this->parser && !str_contains($controller, '::') && 2 === substr_count($controller, ':')) {
5555
// controller in the a:b:c notation then
5656
$deprecatedNotation = $controller;
5757
$controller = $this->parser->parse($deprecatedNotation, false);

Controller/RedirectController.php

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

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

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function process(ContainerBuilder $container)
9999
continue;
100100
}
101101

102-
if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
102+
if (str_contains($definedTag, $tag) || levenshtein($tag, $definedTag) <= \strlen($tag) / 3) {
103103
$candidates[] = $definedTag;
104104
}
105105
}

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12661266
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
12671267
'cache_vary' => [
12681268
'scanned_directories' => array_map(static function (string $dir) use ($projectDir): string {
1269-
return 0 === strpos($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
1269+
return str_starts_with($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir;
12701270
}, $scannedDirectories),
12711271
],
12721272
]

EventListener/ResolveControllerNameSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __call(string $method, array $args)
5555
$event = $args[0];
5656

5757
$controller = $event->getRequest()->attributes->get('_controller');
58-
if (\is_string($controller) && false === strpos($controller, '::') && 2 === substr_count($controller, ':')) {
58+
if (\is_string($controller) && !str_contains($controller, '::') && 2 === substr_count($controller, ':')) {
5959
// controller in the a:b:c notation then
6060
$event->getRequest()->attributes->set('_controller', $parsedNotation = $this->parser->parse($controller, false));
6161

Routing/DelegatingLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function load($resource, $type = null)
9595
continue;
9696
}
9797

98-
if (false !== strpos($controller, '::')) {
98+
if (str_contains($controller, '::')) {
9999
continue;
100100
}
101101

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));

Templating/Helper/CodeHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function abbrClass($class)
6363

6464
public function abbrMethod($method)
6565
{
66-
if (false !== strpos($method, '::')) {
66+
if (str_contains($method, '::')) {
6767
[$class, $method] = explode('::', $method, 2);
6868
$result = sprintf('%s::%s()', $this->abbrClass($class), $method);
6969
} elseif ('Closure' === $method) {
@@ -164,7 +164,7 @@ public function formatFile($file, $line, $text = null)
164164
if (null === $text) {
165165
$file = trim($file);
166166
$fileStr = $file;
167-
if (0 === strpos($fileStr, $this->rootDir)) {
167+
if (str_starts_with($fileStr, $this->rootDir)) {
168168
$fileStr = str_replace(['\\', $this->rootDir], ['/', ''], $fileStr);
169169
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
170170
$fileStr = sprintf('<abbr title="%s">kernel.project_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);

Templating/TemplateNameParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function parse($name)
5050
// normalize name
5151
$name = preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name));
5252

53-
if (false !== strpos($name, '..')) {
53+
if (str_contains($name, '..')) {
5454
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
5555
}
5656

57-
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || 0 === strpos($name, '@')) {
57+
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches) || str_starts_with($name, '@')) {
5858
return parent::parse($name);
5959
}
6060

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());

0 commit comments

Comments
 (0)