Skip to content

Commit 3d5644d

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 16c6e31 commit 3d5644d

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private function groupStaticRoutes(RouteCollection $collection): array
187187
$url = substr($url, 0, -1);
188188
}
189189
foreach ($dynamicRegex as [$hostRx, $rx, $prefix]) {
190-
if (('' === $prefix || 0 === strpos($url, $prefix)) && (preg_match($rx, $url) || preg_match($rx, $url.'/')) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
190+
if (('' === $prefix || str_starts_with($url, $prefix)) && (preg_match($rx, $url) || preg_match($rx, $url.'/')) && (!$host || !$hostRx || preg_match($hostRx, $host))) {
191191
$dynamicRegex[] = [$hostRegex, $regex, $staticPrefix];
192192
$dynamicRoutes->add($name, $route);
193193
continue 2;
@@ -349,7 +349,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
349349
$state->markTail = 0;
350350

351351
// if the regex is too large, throw a signaling exception to recompute with smaller chunk size
352-
set_error_handler(function ($type, $message) { throw false !== strpos($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); });
352+
set_error_handler(function ($type, $message) { throw str_contains($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); });
353353
try {
354354
preg_match($state->regex, '');
355355
} finally {
@@ -427,7 +427,7 @@ private function compileRoute(Route $route, string $name, $vars, bool $hasTraili
427427

428428
if ($condition = $route->getCondition()) {
429429
$condition = $this->getExpressionLanguage()->compile($condition, ['context', 'request']);
430-
$condition = $conditions[$condition] ?? $conditions[$condition] = (false !== strpos($condition, '$request') ? 1 : -1) * \count($conditions);
430+
$condition = $conditions[$condition] ?? $conditions[$condition] = (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
431431
} else {
432432
$condition = null;
433433
}

Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
197197

198198
public static function handleError(int $type, string $msg)
199199
{
200-
return false !== strpos($msg, 'Compilation failed: lookbehind assertion is not fixed length');
200+
return str_contains($msg, 'Compilation failed: lookbehind assertion is not fixed length');
201201
}
202202
}

Matcher/TraceableUrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
6565
$requiredMethods = $route->getMethods();
6666

6767
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
68-
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
68+
if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) {
6969
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
7070
continue;
7171
}

Matcher/UrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
141141
$requiredMethods = $route->getMethods();
142142

143143
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
144-
if ('' !== $staticPrefix && 0 !== strpos($trimmedPathinfo, $staticPrefix)) {
144+
if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo, $staticPrefix)) {
145145
continue;
146146
}
147147
$regex = $compiledRoute->getRegex();

RouteCompiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
135135
} else {
136136
$precedingChar = substr($precedingText, -1);
137137
}
138-
$isSeparator = '' !== $precedingChar && false !== strpos(static::SEPARATORS, $precedingChar);
138+
$isSeparator = '' !== $precedingChar && str_contains(static::SEPARATORS, $precedingChar);
139139

140140
// A PCRE subpattern name must start with a non-digit. Also a PHP variable cannot start with a digit so the
141141
// variable would not be usable as a Controller action argument.
@@ -280,7 +280,7 @@ private static function findNextSeparator(string $pattern, bool $useUtf8): strin
280280
preg_match('/^./u', $pattern, $pattern);
281281
}
282282

283-
return false !== strpos(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
283+
return str_contains(static::SEPARATORS, $pattern[0]) ? $pattern[0] : '';
284284
}
285285

286286
/**

Tests/Loader/FileLocatorStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FileLocatorStub implements FileLocatorInterface
88
{
99
public function locate($name, $currentPath = null, $first = true)
1010
{
11-
if (0 === strpos($name, 'http')) {
11+
if (str_starts_with($name, 'http')) {
1212
return $name;
1313
}
1414

0 commit comments

Comments
 (0)