Skip to content

Commit ea1a3f9

Browse files
Merge branch '5.3' into 5.4
* 5.3: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 758ec96 + 409eba7 commit ea1a3f9

16 files changed

+26
-26
lines changed

Controller/ControllerResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getController(Request $request)
104104
*/
105105
protected function createController(string $controller)
106106
{
107-
if (false === strpos($controller, '::')) {
107+
if (!str_contains($controller, '::')) {
108108
$controller = $this->instantiateController($controller);
109109

110110
if (!\is_callable($controller)) {
@@ -150,7 +150,7 @@ protected function instantiateController(string $class)
150150
private function getControllerError($callable): string
151151
{
152152
if (\is_string($callable)) {
153-
if (false !== strpos($callable, '::')) {
153+
if (str_contains($callable, '::')) {
154154
$callable = explode('::', $callable, 2);
155155
} else {
156156
return sprintf('Function "%s" does not exist.', $callable);
@@ -191,7 +191,7 @@ private function getControllerError($callable): string
191191
foreach ($collection as $item) {
192192
$lev = levenshtein($method, $item);
193193

194-
if ($lev <= \strlen($method) / 3 || false !== strpos($item, $method)) {
194+
if ($lev <= \strlen($method) / 3 || str_contains($item, $method)) {
195195
$alternatives[] = $item;
196196
}
197197
}

DataCollector/DumpDataCollector.php

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

DataCollector/MemoryDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ private function convertToBytes(string $memoryLimit)
102102

103103
$memoryLimit = strtolower($memoryLimit);
104104
$max = strtolower(ltrim($memoryLimit, '+'));
105-
if (0 === strpos($max, '0x')) {
105+
if (str_starts_with($max, '0x')) {
106106
$max = \intval($max, 16);
107-
} elseif (0 === strpos($max, '0')) {
107+
} elseif (str_starts_with($max, '0')) {
108108
$max = \intval($max, 8);
109109
} else {
110110
$max = (int) $max;

DataCollector/RequestDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public function collectSessionUsage(): void
439439
*/
440440
protected function parseController($controller)
441441
{
442-
if (\is_string($controller) && false !== strpos($controller, '::')) {
442+
if (\is_string($controller) && str_contains($controller, '::')) {
443443
$controller = explode('::', $controller);
444444
}
445445

@@ -476,7 +476,7 @@ protected function parseController($controller)
476476
'line' => $r->getStartLine(),
477477
];
478478

479-
if (false !== strpos($r->name, '{closure}')) {
479+
if (str_contains($r->name, '{closure}')) {
480480
return $controller;
481481
}
482482
$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)