diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fdb481fd190a8..3e8de34c124cb 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -11,6 +11,7 @@ '@Symfony' => true, '@Symfony:risky' => true, 'protected_to_private' => false, + 'native_constant_invocation' => ['strict' => false], 'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false], ]) ->setRiskyAllowed(true) diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php index c6b219aa795ab..30f12129c2719 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php @@ -40,7 +40,7 @@ private function pingConnection(EntityManagerInterface $entityManager) try { $connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL()); - } catch (DBALException | Exception $e) { + } catch (DBALException|Exception $e) { $connection->close(); $connection->connect(); } diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 879e87979499c..769beae70ba25 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -230,7 +230,7 @@ private function getMetadata(string $class): ?ClassMetadata { try { return $this->entityManager ? $this->entityManager->getClassMetadata($class) : $this->classMetadataFactory->getMetadataFor($class); - } catch (MappingException | OrmMappingException $exception) { + } catch (MappingException|OrmMappingException $exception) { return null; } } diff --git a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php index f0f9a95652399..b3ab046ebd42b 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php +++ b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php @@ -49,7 +49,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool $className = $metadata->getClassName(); try { $doctrineMetadata = $this->entityManager->getClassMetadata($className); - } catch (MappingException | OrmMappingException $exception) { + } catch (MappingException|OrmMappingException $exception) { return false; } diff --git a/src/Symfony/Component/Cache/Traits/PdoTrait.php b/src/Symfony/Component/Cache/Traits/PdoTrait.php index 5b0461409cfb5..4d5e123005877 100644 --- a/src/Symfony/Component/Cache/Traits/PdoTrait.php +++ b/src/Symfony/Component/Cache/Traits/PdoTrait.php @@ -412,7 +412,7 @@ protected function doSave(array $values, int $lifetime) if (null === $driver && !(\is_object($result) ? $result->rowCount() : $stmt->rowCount())) { try { $insertStmt->execute(); - } catch (DBALException | Exception $e) { + } catch (DBALException|Exception $e) { } catch (\PDOException $e) { // A concurrent write won, let it be } diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index de7b3aedc37ae..0d876b7878820 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1222,11 +1222,11 @@ private function convertToHtmlEntities(string $htmlContent, string $charset = 'U try { return mb_convert_encoding($htmlContent, 'HTML-ENTITIES', $charset); - } catch (\Exception | \ValueError $e) { + } catch (\Exception|\ValueError $e) { try { $htmlContent = iconv($charset, 'UTF-8', $htmlContent); $htmlContent = mb_convert_encoding($htmlContent, 'HTML-ENTITIES', 'UTF-8'); - } catch (\Exception | \ValueError $e) { + } catch (\Exception|\ValueError $e) { } return $htmlContent; diff --git a/src/Symfony/Component/Dotenv/Dotenv.php b/src/Symfony/Component/Dotenv/Dotenv.php index 8180f4bfa10ba..16a252df4f87d 100644 --- a/src/Symfony/Component/Dotenv/Dotenv.php +++ b/src/Symfony/Component/Dotenv/Dotenv.php @@ -54,8 +54,8 @@ public function __construct(bool $usePutenv = true) /** * Loads one or several .env files. * - * @param string $path A file to load - * @param ...string $extraPaths A list of additional files to load + * @param string $path A file to load + * @param string[] ...$extraPaths A list of additional files to load * * @throws FormatException when a file has a syntax error * @throws PathException when a file does not exist or is not readable @@ -112,8 +112,8 @@ public function loadEnv(string $path, string $varName = 'APP_ENV', string $defau /** * Loads one or several .env files and enables override existing vars. * - * @param string $path A file to load - * @param ...string $extraPaths A list of additional files to load + * @param string $path A file to load + * @param string[] ...$extraPaths A list of additional files to load * * @throws FormatException when a file has a syntax error * @throws PathException when a file does not exist or is not readable diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index e234d147e41a1..ed09f72944495 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -626,7 +626,7 @@ protected function doRead($sessionId) $selectStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR); $insertStmt = null; - do { + while (true) { $selectStmt->execute(); $sessionRows = $selectStmt->fetchAll(\PDO::FETCH_NUM); @@ -675,7 +675,7 @@ protected function doRead($sessionId) } return ''; - } while (true); + } } /** diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php index c3df8f9571d44..7b8deeff1ba7e 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php @@ -47,7 +47,7 @@ public function getController(Request $request) if (isset($controller[0]) && \is_string($controller[0]) && isset($controller[1])) { try { $controller[0] = $this->instantiateController($controller[0]); - } catch (\Error | \LogicException $e) { + } catch (\Error|\LogicException $e) { try { // We cannot just check is_callable but have to use reflection because a non-static method // can still be called statically in PHP but we don't want that. This is deprecated in PHP 7, so we @@ -120,7 +120,7 @@ protected function createController($controller) try { $controller = [$this->instantiateController($class), $method]; - } catch (\Error | \LogicException $e) { + } catch (\Error|\LogicException $e) { try { if ((new \ReflectionMethod($class, $method))->isStatic()) { return $class.'::'.$method; diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index cd24c4def6602..7ee02b48fd419 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -127,7 +127,7 @@ public function save(Key $key) try { $stmt->execute(); - } catch (DBALException | Exception $e) { + } catch (DBALException|Exception $e) { // the lock is already acquired. It could be us. Let's try to put off. $this->putOffExpiration($key, $this->initialTtl); } catch (\PDOException $e) { diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index 063724b976219..48d00c4be5ede 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -225,7 +225,7 @@ public function ack(string $id): bool { try { return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0; - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } } @@ -234,7 +234,7 @@ public function reject(string $id): bool { try { return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0; - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } } diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php index 2845943c1f035..3624a875218ae 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php @@ -59,7 +59,7 @@ public function get(): iterable } return []; - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } @@ -77,7 +77,7 @@ public function ack(Envelope $envelope): void { try { $this->connection->ack($this->findDoctrineReceivedStamp($envelope)->getId()); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } } @@ -89,7 +89,7 @@ public function reject(Envelope $envelope): void { try { $this->connection->reject($this->findDoctrineReceivedStamp($envelope)->getId()); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } } @@ -101,7 +101,7 @@ public function getMessageCount(): int { try { return $this->connection->getMessageCount(); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } } @@ -113,7 +113,7 @@ public function all(int $limit = null): iterable { try { $doctrineEnvelopes = $this->connection->findAll($limit); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } @@ -129,7 +129,7 @@ public function find($id): ?Envelope { try { $doctrineEnvelope = $this->connection->find($id); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php index 95f886c12e6a0..bd0cda175d2af 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php @@ -48,7 +48,7 @@ public function send(Envelope $envelope): Envelope try { $id = $this->connection->send($encodedMessage['body'], $encodedMessage['headers'] ?? [], $delay); - } catch (DBALException | Exception $exception) { + } catch (DBALException|Exception $exception) { throw new TransportException($exception->getMessage(), 0, $exception); } diff --git a/src/Symfony/Component/Process/Pipes/AbstractPipes.php b/src/Symfony/Component/Process/Pipes/AbstractPipes.php index 21ab3e389c5be..b0654f13ac431 100644 --- a/src/Symfony/Component/Process/Pipes/AbstractPipes.php +++ b/src/Symfony/Component/Process/Pipes/AbstractPipes.php @@ -133,7 +133,7 @@ protected function write(): ?array } if ($input) { - for (;;) { + while (true) { $data = fread($input, self::CHUNK_SIZE); if (!isset($data[0])) { break; diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 806afbab0948c..6cd41ebcbe15c 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -772,7 +772,8 @@ public function testIterateOverProcessWithTimeout() $start = microtime(true); try { $process->start(); - foreach ($process as $buffer); + foreach ($process as $buffer) { + } $this->fail('A RuntimeException should have been raised'); } catch (RuntimeException $e) { } diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php index e2af5020ec672..e569691612e73 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php @@ -81,7 +81,7 @@ public function authenticate(TokenInterface $token) $this->userChecker->checkPreAuth($user); $this->checkAuthentication($user, $token); $this->userChecker->checkPostAuth($user); - } catch (AccountStatusException | BadCredentialsException $e) { + } catch (AccountStatusException|BadCredentialsException $e) { if ($this->hideUserNotFoundExceptions) { throw new BadCredentialsException('Bad credentials.', 0, $e); } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php index e6d9e06d8b698..f98551f36ad08 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php @@ -160,7 +160,7 @@ public function testHandleNonStringUsernameWithObject(bool $postOnly) /** * @dataProvider postOnlyDataProvider */ - public function testHandleNonStringUsernameWith__toString(bool $postOnly) + public function testHandleNonStringUsernameWithToString(bool $postOnly) { $usernameClass = $this->createMock(DummyUserClass::class); $usernameClass