Skip to content

Commit 5d42a8e

Browse files
Merge branch '5.4' into 6.0
* 5.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents fa5cf43 + ea1a3f9 commit 5d42a8e

15 files changed

+25
-25
lines changed

Controller/ControllerResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getController(Request $request)
9797
*/
9898
protected function createController(string $controller)
9999
{
100-
if (false === strpos($controller, '::')) {
100+
if (!str_contains($controller, '::')) {
101101
$controller = $this->instantiateController($controller);
102102

103103
if (!\is_callable($controller)) {
@@ -143,7 +143,7 @@ protected function instantiateController(string $class)
143143
private function getControllerError(mixed $callable): string
144144
{
145145
if (\is_string($callable)) {
146-
if (false !== strpos($callable, '::')) {
146+
if (str_contains($callable, '::')) {
147147
$callable = explode('::', $callable, 2);
148148
} else {
149149
return sprintf('Function "%s" does not exist.', $callable);
@@ -184,7 +184,7 @@ private function getControllerError(mixed $callable): string
184184
foreach ($collection as $item) {
185185
$lev = levenshtein($method, $item);
186186

187-
if ($lev <= \strlen($method) / 3 || false !== strpos($item, $method)) {
187+
if ($lev <= \strlen($method) / 3 || str_contains($item, $method)) {
188188
$alternatives[] = $item;
189189
}
190190
}

DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public function collect(Request $request, Response $response, \Throwable $except
111111
if (!$this->requestStack
112112
|| !$response->headers->has('X-Debug-Token')
113113
|| $response->isRedirection()
114-
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
114+
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
115115
|| 'html' !== $request->getRequestFormat()
116116
|| false === strripos($response->getContent(), '</body>')
117117
) {
118-
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
118+
if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type'), 'html')) {
119119
$dumper = new HtmlDumper('php://output', $this->charset);
120120
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
121121
} else {

DataCollector/MemoryDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ private function convertToBytes(string $memoryLimit): int|float
8787

8888
$memoryLimit = strtolower($memoryLimit);
8989
$max = strtolower(ltrim($memoryLimit, '+'));
90-
if (0 === strpos($max, '0x')) {
90+
if (str_starts_with($max, '0x')) {
9191
$max = \intval($max, 16);
92-
} elseif (0 === strpos($max, '0')) {
92+
} elseif (str_starts_with($max, '0')) {
9393
$max = \intval($max, 8);
9494
} else {
9595
$max = (int) $max;

DataCollector/RequestDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public function collectSessionUsage(): void
433433
*/
434434
protected function parseController(array|object|string|null $controller)
435435
{
436-
if (\is_string($controller) && false !== strpos($controller, '::')) {
436+
if (\is_string($controller) && str_contains($controller, '::')) {
437437
$controller = explode('::', $controller);
438438
}
439439

@@ -470,7 +470,7 @@ protected function parseController(array|object|string|null $controller)
470470
'line' => $r->getStartLine(),
471471
];
472472

473-
if (false !== strpos($r->name, '{closure}')) {
473+
if (str_contains($r->name, '{closure}')) {
474474
return $controller;
475475
}
476476
$controller['method'] = $r->name;

Debug/FileLinkFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function format(string $file, int $line)
6060
{
6161
if ($fmt = $this->getFileLinkFormat()) {
6262
for ($i = 1; isset($fmt[$i]); ++$i) {
63-
if (0 === strpos($file, $k = $fmt[$i++])) {
63+
if (str_starts_with($file, $k = $fmt[$i++])) {
6464
$file = substr_replace($file, $fmt[$i], 0, \strlen($k));
6565
break;
6666
}

DependencyInjection/AddAnnotatedClassesToCachePass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function expandClasses(array $patterns, array $classes): array
6262

6363
// Explicit classes declared in the patterns are returned directly
6464
foreach ($patterns as $key => $pattern) {
65-
if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) {
65+
if (!str_ends_with($pattern, '\\') && !str_contains($pattern, '*')) {
6666
unset($patterns[$key]);
6767
$expanded[] = ltrim($pattern, '\\');
6868
}
@@ -127,10 +127,10 @@ private function patternsToRegexps(array $patterns): array
127127

128128
private function matchAnyRegexps(string $class, array $regexps): bool
129129
{
130-
$isTest = false !== strpos($class, 'Test');
130+
$isTest = str_contains($class, 'Test');
131131

132132
foreach ($regexps as $regex) {
133-
if ($isTest && false === strpos($regex, 'Test')) {
133+
if ($isTest && !str_contains($regex, 'Test')) {
134134
continue;
135135
}
136136

EventListener/AbstractTestSessionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function onKernelResponse(ResponseEvent $event)
8383
if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) {
8484
$params = session_get_cookie_params() + ['samesite' => null];
8585
foreach ($this->sessionOptions as $k => $v) {
86-
if (0 === strpos($k, 'cookie_')) {
86+
if (str_starts_with($k, 'cookie_')) {
8787
$params[substr($k, 7)] = $v;
8888
}
8989
}

Exception/ControllerDoesNotReturnResponseException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(string $message, callable $controller, string $file,
3838

3939
private function parseControllerDefinition(callable $controller): ?array
4040
{
41-
if (\is_string($controller) && false !== strpos($controller, '::')) {
41+
if (\is_string($controller) && str_contains($controller, '::')) {
4242
$controller = explode('::', $controller);
4343
}
4444

HttpCache/AbstractSurrogate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function hasSurrogateCapability(Request $request)
5757
return false;
5858
}
5959

60-
return false !== strpos($value, sprintf('%s/1.0', strtoupper($this->getName())));
60+
return str_contains($value, sprintf('%s/1.0', strtoupper($this->getName())));
6161
}
6262

6363
/**

HttpCache/Esi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getName()
3737
*/
3838
public function addSurrogateControl(Response $response)
3939
{
40-
if (false !== strpos($response->getContent(), '<esi:include')) {
40+
if (str_contains($response->getContent(), '<esi:include')) {
4141
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
4242
}
4343
}

0 commit comments

Comments
 (0)