diff --git a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php index ce241369265fe..3275ea792672b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php @@ -224,7 +224,7 @@ private function hasHashOrNonce(array $directives): bool if (!str_ends_with($directive, '\'')) { continue; } - if ('\'nonce-' === substr($directive, 0, 7)) { + if (str_starts_with($directive, '\'nonce-')) { return true; } if (\in_array(substr($directive, 0, 8), ['\'sha256-', '\'sha384-', '\'sha512-'], true)) { diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index bc47f6e104da6..fd11a84d80a47 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -254,7 +254,7 @@ private function applyCurrentStyle(string $text, string $current, int $width, in $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); $text = rtrim($text, "\n").($matches[1] ?? ''); - if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { + if (!$currentLineLength && '' !== $current && !str_ends_with($current, "\n")) { $text = "\n".$text; } diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php index 12703b3d29ed2..5d2703e8cff72 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php @@ -117,7 +117,7 @@ private function patternsToRegexps(array $patterns): array $regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']); // If this class does not end by a slash, anchor the end - if ('\\' !== substr($regex, -1)) { + if (!str_ends_with($regex, '\\')) { $regex .= '$'; } diff --git a/src/Symfony/Component/Mime/Tests/Encoder/Rfc2231EncoderTest.php b/src/Symfony/Component/Mime/Tests/Encoder/Rfc2231EncoderTest.php index 47cb3954f0665..2dcda7aeb5052 100644 --- a/src/Symfony/Component/Mime/Tests/Encoder/Rfc2231EncoderTest.php +++ b/src/Symfony/Component/Mime/Tests/Encoder/Rfc2231EncoderTest.php @@ -102,7 +102,7 @@ public function testEncodingAndDecodingSamples() $dir = realpath(__DIR__.'/../Fixtures/samples/charsets'); $sampleFp = opendir($dir); while (false !== $encoding = readdir($sampleFp)) { - if ('.' == substr($encoding, 0, 1)) { + if (str_starts_with($encoding, '.')) { continue; } @@ -110,7 +110,7 @@ public function testEncodingAndDecodingSamples() if (is_dir($dir.'/'.$encoding)) { $fileFp = opendir($dir.'/'.$encoding); while (false !== $sampleFile = readdir($fileFp)) { - if ('.' == substr($sampleFile, 0, 1)) { + if (str_starts_with($sampleFile, '.')) { continue; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index c1ca8faff5474..d022ab167f0f4 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -37,7 +37,7 @@ public function load(mixed $path, string $type = null): RouteCollection new \RecursiveCallbackFilterIterator( new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS), function (\SplFileInfo $current) { - return '.' !== substr($current->getBasename(), 0, 1); + return !str_starts_with($current->getBasename(), '.'); } ), \RecursiveIteratorIterator::LEAVES_ONLY diff --git a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php index 76b00b151aa06..6f14fd39bfa44 100644 --- a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php @@ -45,7 +45,7 @@ protected function loadResource(string $resource): array continue; } - if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === \count($data)) { + if (!str_starts_with($data[0], '#') && isset($data[1]) && 2 === \count($data)) { $messages[$data[0]] = $data[1]; } } diff --git a/src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php b/src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php index 1b9b5f522bed2..f6b2536372019 100644 --- a/src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php +++ b/src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php @@ -237,7 +237,7 @@ private function getTransitionEscapedWithStyle(MetadataStoreInterface $workflowM private function getTransitionColor(string $color): string { // PUML format requires that color in transition have to be prefixed with “#”. - if ('#' !== substr($color, 0, 1)) { + if (!str_starts_with($color, '#')) { $color = '#'.$color; }