diff --git a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php index c80177c5d39c0..4fb751d4bfb32 100644 --- a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php +++ b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php @@ -115,7 +115,7 @@ public function loginUser(object $user, string $firewallContext = 'main'): stati } if (!$user instanceof UserInterface) { - throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user))); + throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, get_debug_type($user))); } $token = new TestBrowserToken($user->getRoles(), $user, $firewallContext); diff --git a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php index 87abb6a086f48..e19e05cfdaf6a 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php @@ -193,7 +193,7 @@ private function writeLine(string $text, int $indent = 0) private function writeArray(array $array, int $depth) { - $isIndexed = array_values($array) === $array; + $isIndexed = array_is_list($array); foreach ($array as $key => $value) { if (\is_array($value)) { diff --git a/src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorTextContains.php b/src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorTextContains.php index 83305808ddd42..751b4274dad74 100644 --- a/src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorTextContains.php +++ b/src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorTextContains.php @@ -56,7 +56,7 @@ protected function matches($crawler): bool $this->hasNode = true; $this->nodeText = $crawler->text(null, true); - return false !== mb_strpos($this->nodeText, $this->expectedText); + return str_contains($this->nodeText, $this->expectedText); } /** diff --git a/src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php b/src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php index c3e7a8674e743..8468fa76f4b32 100644 --- a/src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php +++ b/src/Symfony/Component/ErrorHandler/Resources/views/exception.html.php @@ -35,7 +35,7 @@ $last = $exceptionAsArrayCount - 1; foreach ($exceptionAsArray as $i => $e) { foreach ($e['trace'] as $trace) { - if ($trace['file'] && false === mb_strpos($trace['file'], '/vendor/') && false === mb_strpos($trace['file'], '/var/cache/') && $i < $last) { + if ($trace['file'] && !str_contains($trace['file'], '/vendor/') && !str_contains($trace['file'], '/var/cache/') && $i < $last) { $exceptionWithUserCode[] = $i; } } diff --git a/src/Symfony/Component/ErrorHandler/Resources/views/traces.html.php b/src/Symfony/Component/ErrorHandler/Resources/views/traces.html.php index f64d917138258..6ef37d67496bd 100644 --- a/src/Symfony/Component/ErrorHandler/Resources/views/traces.html.php +++ b/src/Symfony/Component/ErrorHandler/Resources/views/traces.html.php @@ -31,7 +31,7 @@ $trace) { - $isVendorTrace = $trace['file'] && (false !== mb_strpos($trace['file'], '/vendor/') || false !== mb_strpos($trace['file'], '/var/cache/')); + $isVendorTrace = $trace['file'] && (str_contains($trace['file'], '/vendor/') || str_contains($trace['file'], '/var/cache/')); $displayCodeSnippet = $isFirstUserCode && !$isVendorTrace; if ($displayCodeSnippet) { $isFirstUserCode = false; diff --git a/src/Symfony/Component/Filesystem/Path.php b/src/Symfony/Component/Filesystem/Path.php index 0bbd5b4772aff..17e73a018a623 100644 --- a/src/Symfony/Component/Filesystem/Path.php +++ b/src/Symfony/Component/Filesystem/Path.php @@ -574,7 +574,7 @@ public static function makeRelative(string $path, string $basePath): string */ public static function isLocal(string $path): bool { - return '' !== $path && false === mb_strpos($path, '://'); + return '' !== $path && !str_contains($path, '://'); } /** @@ -638,7 +638,7 @@ public static function getLongestCommonBasePath(string ...$paths): ?string // Prevent false positives for common prefixes // see isBasePath() - if (0 === mb_strpos($path.'/', $basePath.'/')) { + if (str_starts_with($path.'/', $basePath.'/')) { // next path continue 2; } @@ -666,7 +666,7 @@ public static function join(string ...$paths): string if (null === $finalPath) { // For first part we keep slashes, like '/top', 'C:\' or 'phar://' $finalPath = $path; - $wasScheme = (false !== mb_strpos($path, '://')); + $wasScheme = str_contains($path, '://'); continue; } @@ -717,7 +717,7 @@ public static function isBasePath(string $basePath, string $ofPath): bool // Don't append a slash for the root "/", because then that root // won't be discovered as common prefix ("//" is not a prefix of // "/foobar/"). - return 0 === mb_strpos($ofPath.'/', rtrim($basePath, '/').'/'); + return str_starts_with($ofPath.'/', rtrim($basePath, '/').'/'); } /** @@ -786,7 +786,7 @@ private static function split(string $path): array $length = mb_strlen($path); // Remove and remember root directory - if (0 === mb_strpos($path, '/')) { + if (str_starts_with($path, '/')) { $root .= '/'; $path = $length > 1 ? mb_substr($path, 1) : ''; } elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) { diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 394f6a89f2b19..f404aece2557b 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -704,7 +704,7 @@ public function isEmpty(): bool return FormUtil::isEmpty($this->modelData) || // arrays, countables - ((\is_array($this->modelData) || $this->modelData instanceof \Countable) && 0 === \count($this->modelData)) || + (is_countable($this->modelData) && 0 === \count($this->modelData)) || // traversables that are not countable ($this->modelData instanceof \Traversable && 0 === iterator_count($this->modelData)); } diff --git a/src/Symfony/Component/HttpClient/MockHttpClient.php b/src/Symfony/Component/HttpClient/MockHttpClient.php index bce20971fdbb4..8df09120295dc 100644 --- a/src/Symfony/Component/HttpClient/MockHttpClient.php +++ b/src/Symfony/Component/HttpClient/MockHttpClient.php @@ -81,7 +81,7 @@ public function request(string $method, string $url, array $options = []): Respo ++$this->requestsCount; if (!$response instanceof ResponseInterface) { - throw new TransportException(sprintf('The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "%s" given.', \is_object($response) ? \get_class($response) : \gettype($response))); + throw new TransportException(sprintf('The response factory passed to MockHttpClient must return/yield an instance of ResponseInterface, "%s" given.', get_debug_type($response))); } return MockResponse::fromRequest($method, $url, $options, $response); diff --git a/src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php b/src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php index 67ab85eb693f0..c9e0dc25b6987 100644 --- a/src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php +++ b/src/Symfony/Component/Mime/Test/Constraint/EmailHtmlBodyContains.php @@ -43,7 +43,7 @@ protected function matches($message): bool throw new \LogicException('Unable to test a message HTML body on a RawMessage or Message instance.'); } - return false !== mb_strpos($message->getHtmlBody(), $this->expectedText); + return str_contains($message->getHtmlBody(), $this->expectedText); } /** diff --git a/src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php b/src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php index f31655fd0fc52..4f55ce04bcb79 100644 --- a/src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php +++ b/src/Symfony/Component/Mime/Test/Constraint/EmailTextBodyContains.php @@ -43,7 +43,7 @@ protected function matches($message): bool throw new \LogicException('Unable to test a message text body on a RawMessage or Message instance.'); } - return false !== mb_strpos($message->getTextBody(), $this->expectedText); + return str_contains($message->getTextBody(), $this->expectedText); } /** diff --git a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php index b36a9c5826aba..e174dfbfcbc5f 100644 --- a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php +++ b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php @@ -91,7 +91,7 @@ public function supports(Request $request): ?bool if (null !== $this->logger) { $context = ['firewall_name' => $this->firewallName]; - if ($this->authenticators instanceof \Countable || \is_array($this->authenticators)) { + if (is_countable($this->authenticators)) { $context['authenticators'] = \count($this->authenticators); } diff --git a/src/Symfony/Component/Semaphore/Store/RedisStore.php b/src/Symfony/Component/Semaphore/Store/RedisStore.php index bcc07cfeeaec4..153a39bb5182c 100644 --- a/src/Symfony/Component/Semaphore/Store/RedisStore.php +++ b/src/Symfony/Component/Semaphore/Store/RedisStore.php @@ -190,7 +190,7 @@ private function evaluate(string $script, string $resource, array $args): mixed return $this->redis->eval(...array_merge([$script, 1, $resource], $args)); } - throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis))); + throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($this->redis))); } private function getUniqueToken(Key $key): string diff --git a/src/Symfony/Component/String/AbstractString.php b/src/Symfony/Component/String/AbstractString.php index b66e3d20e4f52..75c9d3304e14c 100644 --- a/src/Symfony/Component/String/AbstractString.php +++ b/src/Symfony/Component/String/AbstractString.php @@ -558,7 +558,7 @@ abstract public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF */ public function trimPrefix($prefix): static { - if (\is_array($prefix) || $prefix instanceof \Traversable) { + if (is_iterable($prefix)) { foreach ($prefix as $s) { $t = $this->trimPrefix($s); @@ -592,7 +592,7 @@ abstract public function trimStart(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FE */ public function trimSuffix($suffix): static { - if (\is_array($suffix) || $suffix instanceof \Traversable) { + if (is_iterable($suffix)) { foreach ($suffix as $s) { $t = $this->trimSuffix($s);