Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use str_ends_with() and str_starts_with() #44499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '$';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public function testEncodingAndDecodingSamples()
$dir = realpath(__DIR__.'/../Fixtures/samples/charsets');
$sampleFp = opendir($dir);
while (false !== $encoding = readdir($sampleFp)) {
if ('.' == substr($encoding, 0, 1)) {
alexislefebvre marked this conversation as resolved.
Show resolved Hide resolved
if (str_starts_with($encoding, '.')) {
continue;
}

$encoder = new Rfc2231Encoder();
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Translation/Loader/CsvFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Workflow/Dumper/PlantUmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.