Skip to content

Commit ac84385

Browse files
committed
Leverage str_starts_with(), str_ends_with() and str_contains()
1 parent 81748f3 commit ac84385

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function getAlternatives(string $id): array
9595
}
9696

9797
$lev = levenshtein($id, $knownId);
98-
if ($lev <= \strlen($id) / 3 || false !== strpos($knownId, $id)) {
98+
if ($lev <= \strlen($id) / 3 || str_contains($knownId, $id)) {
9999
$alternatives[] = $knownId;
100100
}
101101
}

Dumper/GraphvizDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private function findNodes(): array
155155
foreach ($container->getDefinitions() as $id => $definition) {
156156
$class = $definition->getClass();
157157

158-
if ('\\' === substr($class, 0, 1)) {
158+
if (str_starts_with($class, '\\')) {
159159
$class = substr($class, 1);
160160
}
161161

Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,10 +2123,10 @@ private function doExport(mixed $value, bool $resolveEnv = false): mixed
21232123
$export = var_export($value, true);
21242124
}
21252125
if ($this->asFiles) {
2126-
if (false !== strpos($export, '$this')) {
2126+
if (str_contains($export, '$this')) {
21272127
$export = str_replace('$this', "$'.'this", $export);
21282128
}
2129-
if (false !== strpos($export, 'function () {')) {
2129+
if (str_contains($export, 'function () {')) {
21302130
$export = str_replace('function () {', "function ('.') {", $export);
21312131
}
21322132
}

Dumper/Preloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static function append(string $file, array $list): void
2626
$classes = [];
2727

2828
foreach ($list as $item) {
29-
if (0 === strpos($item, $cacheDir)) {
29+
if (str_starts_with($item, $cacheDir)) {
3030
file_put_contents($file, sprintf("require_once __DIR__.%s;\n", var_export(strtr(substr($item, \strlen($cacheDir)), \DIRECTORY_SEPARATOR, '/'), true)), \FILE_APPEND);
3131
continue;
3232
}

Dumper/XmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa
9494
$service->setAttribute('id', $id);
9595
}
9696
if ($class = $definition->getClass()) {
97-
if ('\\' === substr($class, 0, 1)) {
97+
if (str_starts_with($class, '\\')) {
9898
$class = substr($class, 1);
9999
}
100100

Dumper/YamlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private function addService(string $id, Definition $definition): string
5757
{
5858
$code = " $id:\n";
5959
if ($class = $definition->getClass()) {
60-
if ('\\' === substr($class, 0, 1)) {
60+
if (str_starts_with($class, '\\')) {
6161
$class = substr($class, 1);
6262
}
6363

Loader/PhpFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ private function configBuilder(string $namespace): ConfigBuilderInterface
173173
}
174174

175175
// If it does not start with Symfony\Config\ we dont know how to handle this
176-
if ('Symfony\\Config\\' !== substr($namespace, 0, 15)) {
176+
if (!str_starts_with($namespace, 'Symfony\\Config\\')) {
177177
throw new InvalidArgumentException(sprintf('Could not find or generate class "%s".', $namespace));
178178
}
179179

180180
// Try to get the extension alias
181181
$alias = Container::underscore(substr($namespace, 15, -6));
182182

183-
if (false !== strpos($alias, '\\')) {
183+
if (str_contains($alias, '\\')) {
184184
throw new InvalidArgumentException('You can only use "root" ConfigBuilders from "Symfony\\Config\\" namespace. Nested classes like "Symfony\\Config\\Framework\\CacheConfig" cannot be used.');
185185
}
186186

Loader/YamlFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ private function validate(mixed $content, string $file): ?array
776776
}
777777

778778
foreach ($content as $namespace => $data) {
779-
if (\in_array($namespace, ['imports', 'parameters', 'services']) || 0 === strpos($namespace, 'when@')) {
779+
if (\in_array($namespace, ['imports', 'parameters', 'services']) || str_starts_with($namespace, 'when@')) {
780780
continue;
781781
}
782782

@@ -914,7 +914,7 @@ private function resolveServices(mixed $value, string $file, bool $isParameter =
914914
private function loadFromExtensions(array $content)
915915
{
916916
foreach ($content as $namespace => $values) {
917-
if (\in_array($namespace, ['imports', 'parameters', 'services']) || 0 === strpos($namespace, 'when@')) {
917+
if (\in_array($namespace, ['imports', 'parameters', 'services']) || str_starts_with($namespace, 'when@')) {
918918
continue;
919919
}
920920

0 commit comments

Comments
 (0)