Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28d4d6b

Browse files
alexislefebvreGromNaN
authored andcommitted
Use str_ends_with() and str_starts_with()
1 parent 94533d4 commit 28d4d6b

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

src/Symfony/Bundle/WebProfilerBundle/Csp/ContentSecurityPolicyHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private function hasHashOrNonce(array $directives): bool
224224
if (!str_ends_with($directive, '\'')) {
225225
continue;
226226
}
227-
if ('\'nonce-' === substr($directive, 0, 7)) {
227+
if (str_starts_with($directive, '\'nonce-')) {
228228
return true;
229229
}
230230
if (\in_array(substr($directive, 0, 8), ['\'sha256-', '\'sha384-', '\'sha512-'], true)) {

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function applyCurrentStyle(string $text, string $current, int $width, in
254254
$text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text);
255255
$text = rtrim($text, "\n").($matches[1] ?? '');
256256

257-
if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) {
257+
if (!$currentLineLength && '' !== $current && !str_ends_with($current, "\n")) {
258258
$text = "\n".$text;
259259
}
260260

src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function patternsToRegexps(array $patterns): array
117117
$regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']);
118118

119119
// If this class does not end by a slash, anchor the end
120-
if ('\\' !== substr($regex, -1)) {
120+
if (!str_ends_with($regex, '\\')) {
121121
$regex .= '$';
122122
}
123123

src/Symfony/Component/Mime/Tests/Encoder/Rfc2231EncoderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public function testEncodingAndDecodingSamples()
102102
$dir = realpath(__DIR__.'/../Fixtures/samples/charsets');
103103
$sampleFp = opendir($dir);
104104
while (false !== $encoding = readdir($sampleFp)) {
105-
if ('.' == substr($encoding, 0, 1)) {
105+
if (str_starts_with($encoding, '.')) {
106106
continue;
107107
}
108108

109109
$encoder = new Rfc2231Encoder();
110110
if (is_dir($dir.'/'.$encoding)) {
111111
$fileFp = opendir($dir.'/'.$encoding);
112112
while (false !== $sampleFile = readdir($fileFp)) {
113-
if ('.' == substr($sampleFile, 0, 1)) {
113+
if (str_starts_with($sampleFile, '.')) {
114114
continue;
115115
}
116116

src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function load(mixed $path, string $type = null): RouteCollection
3737
new \RecursiveCallbackFilterIterator(
3838
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
3939
function (\SplFileInfo $current) {
40-
return '.' !== substr($current->getBasename(), 0, 1);
40+
return !str_starts_with($current->getBasename(), '.');
4141
}
4242
),
4343
\RecursiveIteratorIterator::LEAVES_ONLY

src/Symfony/Component/Translation/Loader/CsvFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function loadResource(string $resource): array
4545
continue;
4646
}
4747

48-
if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === \count($data)) {
48+
if (!str_starts_with($data[0], '#') && isset($data[1]) && 2 === \count($data)) {
4949
$messages[$data[0]] = $data[1];
5050
}
5151
}

src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function getTransitionEscapedWithStyle(MetadataStoreInterface $workflowM
237237
private function getTransitionColor(string $color): string
238238
{
239239
// PUML format requires that color in transition have to be prefixed with “#”.
240-
if ('#' !== substr($color, 0, 1)) {
240+
if (!str_starts_with($color, '#')) {
241241
$color = '#'.$color;
242242
}
243243

0 commit comments

Comments
 (0)