Skip to content

Commit 882946c

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 21336db commit 882946c

17 files changed

+29
-29
lines changed

Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function getScript($request)
8585

8686
$requires = '';
8787
foreach (get_declared_classes() as $class) {
88-
if (0 === strpos($class, 'ComposerAutoloaderInit')) {
88+
if (str_starts_with($class, 'ComposerAutoloaderInit')) {
8989
$r = new \ReflectionClass($class);
9090
$file = \dirname($r->getFileName(), 2).'/autoload.php';
9191
if (file_exists($file)) {

Config/FileLocator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function locate($file, $currentPath = null, $first = true)
7070
// no need to trigger deprecations when the loaded file is given as absolute path
7171
foreach ($this->paths as $deprecatedPath) {
7272
foreach ((array) $locations as $location) {
73-
if (null !== $currentPath && 0 === strpos($location, $currentPath)) {
73+
if (null !== $currentPath && str_starts_with($location, $currentPath)) {
7474
return $locations;
7575
}
7676

77-
if (0 === strpos($location, $deprecatedPath) && (null === $currentPath || false === strpos($location, $currentPath))) {
77+
if (str_starts_with($location, $deprecatedPath) && (null === $currentPath || !str_contains($location, $currentPath))) {
7878
$deprecation = sprintf('Loading the file "%s" from the global resource directory "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $file, $deprecatedPath);
7979
}
8080
}

Controller/ControllerResolver.php

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

112112
if (!\is_callable($controller)) {
@@ -154,7 +154,7 @@ protected function instantiateController($class)
154154
private function getControllerError($callable): string
155155
{
156156
if (\is_string($callable)) {
157-
if (false !== strpos($callable, '::')) {
157+
if (str_contains($callable, '::')) {
158158
$callable = explode('::', $callable, 2);
159159
} else {
160160
return sprintf('Function "%s" does not exist.', $callable);
@@ -195,7 +195,7 @@ private function getControllerError($callable): string
195195
foreach ($collection as $item) {
196196
$lev = levenshtein($method, $item);
197197

198-
if ($lev <= \strlen($method) / 3 || false !== strpos($item, $method)) {
198+
if ($lev <= \strlen($method) / 3 || str_contains($item, $method)) {
199199
$alternatives[] = $item;
200200
}
201201
}

DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ public function collect(Request $request, Response $response/*, \Throwable $exce
120120
if (!$this->requestStack
121121
|| !$response->headers->has('X-Debug-Token')
122122
|| $response->isRedirection()
123-
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
123+
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
124124
|| 'html' !== $request->getRequestFormat()
125125
|| false === strripos($response->getContent(), '</body>')
126126
) {
127-
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
127+
if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type'), 'html')) {
128128
$dumper = new HtmlDumper('php://output', $this->charset);
129129
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
130130
} else {

DataCollector/MemoryDataCollector.php

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

105105
$memoryLimit = strtolower($memoryLimit);
106106
$max = strtolower(ltrim($memoryLimit, '+'));
107-
if (0 === strpos($max, '0x')) {
107+
if (str_starts_with($max, '0x')) {
108108
$max = \intval($max, 16);
109-
} elseif (0 === strpos($max, '0')) {
109+
} elseif (str_starts_with($max, '0')) {
110110
$max = \intval($max, 8);
111111
} else {
112112
$max = (int) $max;

DataCollector/RequestDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function getName()
394394
*/
395395
protected function parseController($controller)
396396
{
397-
if (\is_string($controller) && false !== strpos($controller, '::')) {
397+
if (\is_string($controller) && str_contains($controller, '::')) {
398398
$controller = explode('::', $controller);
399399
}
400400

@@ -431,7 +431,7 @@ protected function parseController($controller)
431431
'line' => $r->getStartLine(),
432432
];
433433

434-
if (false !== strpos($r->name, '{closure}')) {
434+
if (str_contains($r->name, '{closure}')) {
435435
return $controller;
436436
}
437437
$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($file, $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 (!str_ends_with($pattern, '\\') && 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(FilterResponseEvent $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

0 commit comments

Comments
 (0)