Skip to content

Commit 380b152

Browse files
Merge branch '4.4' into 5.2
* 4.4: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents 6d39bab + 882946c commit 380b152

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
@@ -50,7 +50,7 @@ public function format(string $file, int $line)
5050
{
5151
if ($fmt = $this->getFileLinkFormat()) {
5252
for ($i = 1; isset($fmt[$i]); ++$i) {
53-
if (0 === strpos($file, $k = $fmt[$i++])) {
53+
if (str_starts_with($file, $k = $fmt[$i++])) {
5454
$file = substr_replace($file, $fmt[$i], 0, \strlen($k));
5555
break;
5656
}

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
@@ -81,7 +81,7 @@ public function onKernelResponse(ResponseEvent $event)
8181
if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) {
8282
$params = session_get_cookie_params() + ['samesite' => null];
8383
foreach ($this->sessionOptions as $k => $v) {
84-
if (0 === strpos($k, 'cookie_')) {
84+
if (str_starts_with($k, 'cookie_')) {
8585
$params[substr($k, 7)] = $v;
8686
}
8787
}

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
}

HttpCache/Ssi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getName()
3434
*/
3535
public function addSurrogateControl(Response $response)
3636
{
37-
if (false !== strpos($response->getContent(), '<!--#include')) {
37+
if (str_contains($response->getContent(), '<!--#include')) {
3838
$response->headers->set('Surrogate-Control', 'content="SSI/1.0"');
3939
}
4040
}

Kernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ public function locateResource(string $name)
237237
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
238238
}
239239

240-
if (false !== strpos($name, '..')) {
240+
if (str_contains($name, '..')) {
241241
throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
242242
}
243243

244244
$bundleName = substr($name, 1);
245245
$path = '';
246-
if (false !== strpos($bundleName, '/')) {
246+
if (str_contains($bundleName, '/')) {
247247
[$bundleName, $path] = explode('/', $bundleName, 2);
248248
}
249249

@@ -404,7 +404,7 @@ protected function build(ContainerBuilder $container)
404404
protected function getContainerClass()
405405
{
406406
$class = static::class;
407-
$class = false !== strpos($class, "@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class;
407+
$class = str_contains($class, "@anonymous\0") ? get_parent_class($class).str_replace('.', '_', ContainerBuilder::hash($class)) : $class;
408408
$class = str_replace('\\', '_', $class).ucfirst($this->environment).($this->debug ? 'Debug' : '').'Container';
409409

410410
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) {

Log/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function log($level, $message, array $context = [])
8888

8989
private function format(string $level, string $message, array $context, bool $prefixDate = true): string
9090
{
91-
if (false !== strpos($message, '{')) {
91+
if (str_contains($message, '{')) {
9292
$replacements = [];
9393
foreach ($context as $key => $val) {
9494
if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {

Profiler/FileProfilerStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
3434
*/
3535
public function __construct(string $dsn)
3636
{
37-
if (0 !== strpos($dsn, 'file:')) {
37+
if (!str_starts_with($dsn, 'file:')) {
3838
throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use FileStorage with an invalid dsn "%s". The expected format is "file:/path/to/the/storage/folder".', $dsn));
3939
}
4040
$this->folder = substr($dsn, 5);
@@ -64,7 +64,7 @@ public function find(?string $ip, ?string $url, ?int $limit, ?string $method, in
6464
[$csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode] = $values;
6565
$csvTime = (int) $csvTime;
6666

67-
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) {
67+
if ($ip && !str_contains($csvIp, $ip) || $url && !str_contains($csvUrl, $url) || $method && !str_contains($csvMethod, $method) || $statusCode && !str_contains($csvStatusCode, $statusCode)) {
6868
continue;
6969
}
7070

Tests/EventListener/RouterListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHtt
6060

6161
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
6262
$this->assertEquals($expectedHttpsPort, $context->getHttpsPort());
63-
$this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme());
63+
$this->assertEquals(str_starts_with($uri, 'https') ? 'https' : 'http', $context->getScheme());
6464
}
6565

6666
public function getPortData()

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/http-foundation": "^4.4|^5.0",
2525
"symfony/polyfill-ctype": "^1.8",
2626
"symfony/polyfill-php73": "^1.9",
27-
"symfony/polyfill-php80": "^1.15",
27+
"symfony/polyfill-php80": "^1.16",
2828
"psr/log": "^1|^2"
2929
},
3030
"require-dev": {

0 commit comments

Comments
 (0)