Skip to content

Commit d6e4f59

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
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()) {

0 commit comments

Comments
 (0)