From 3df647110125d4ca0510f50213256859702e598b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 26 Jul 2023 17:12:55 +0200 Subject: [PATCH] More short closures + isset instead of null checks + etc. --- .github/expected-missing-return-types.diff | 24 +++--- .../Controller/AbstractController.php | 3 +- .../Bundle/FrameworkBundle/Routing/Router.php | 2 +- .../Security/Factory/AccessTokenFactory.php | 10 +-- src/Symfony/Component/BrowserKit/Cookie.php | 8 +- .../Cache/Adapter/CouchbaseBucketAdapter.php | 2 +- .../Adapter/CouchbaseCollectionAdapter.php | 2 +- .../Cache/Adapter/DoctrineDbalAdapter.php | 3 +- .../Cache/Adapter/MemcachedAdapter.php | 7 +- .../Component/Cache/Adapter/PdoAdapter.php | 3 +- src/Symfony/Component/Cache/LockRegistry.php | 2 +- .../Cache/Traits/FilesystemCommonTrait.php | 10 +-- .../Builder/ArrayNodeDefinition.php | 10 +-- .../Definition/Builder/NodeDefinition.php | 4 +- .../Config/Definition/Builder/TreeBuilder.php | 2 +- .../Builder/VariableNodeDefinition.php | 6 +- .../Definition/Builder/ExprBuilderTest.php | 2 +- .../Compiler/AutowirePass.php | 2 +- .../DependencyInjection/Dumper/PhpDumper.php | 2 +- .../Configurator/AbstractConfigurator.php | 2 +- .../Tests/Fixtures/php/services10.php | 2 +- .../Tests/Fixtures/php/services12.php | 2 +- .../Tests/Fixtures/php/services19.php | 2 +- .../Tests/Fixtures/php/services26.php | 2 +- .../Tests/Fixtures/php/services8.php | 2 +- .../Tests/Fixtures/php/services9_as_files.txt | 2 +- .../Tests/Fixtures/php/services9_compiled.php | 2 +- .../php/services9_inlined_factories.txt | 2 +- .../php/services9_lazy_inlined_factories.txt | 2 +- .../Fixtures/php/services_array_params.php | 2 +- .../Fixtures/php/services_base64_env.php | 2 +- .../Tests/Fixtures/php/services_csv_env.php | 2 +- .../Fixtures/php/services_default_env.php | 2 +- .../php/services_deprecated_parameters.php | 2 +- ...ervices_deprecated_parameters_as_files.txt | 2 +- .../Tests/Fixtures/php/services_env_in_id.php | 2 +- .../php/services_errored_definition.php | 2 +- .../Tests/Fixtures/php/services_json_env.php | 2 +- .../php/services_query_string_env.php | 2 +- .../Tests/Fixtures/php/services_rot13_env.php | 2 +- .../php/services_unsupported_characters.php | 2 +- .../Tests/Fixtures/php/services_url_env.php | 2 +- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- .../Component/ErrorHandler/ErrorHandler.php | 2 +- .../Tests/Debug/WrappedListenerTest.php | 2 +- .../ExpressionLanguage/Node/BinaryNode.php | 6 +- .../Tests/Node/BinaryNodeTest.php | 2 +- .../Form/ChoiceList/ArrayChoiceList.php | 2 +- .../Component/Form/Test/TypeTestCase.php | 7 -- .../Constraints/FormValidatorTest.php | 16 ++-- .../ViolationMapper/ViolationMapperTest.php | 4 +- .../HttpFoundation/BinaryFileResponse.php | 2 +- .../Component/HttpFoundation/Request.php | 80 ++++++++----------- .../HttpFoundation/StreamedResponse.php | 6 +- .../HttpKernel/Tests/HttpKernelTest.php | 28 +++---- .../Component/Ldap/Adapter/ExtLdap/Query.php | 2 - .../Dumper/CompiledUrlMatcherDumper.php | 2 +- src/Symfony/Component/Routing/Router.php | 8 +- .../Exception/AuthenticationException.php | 28 ------- .../Serializer/Encoder/JsonDecode.php | 3 + .../Component/String/AbstractString.php | 4 +- .../String/AbstractUnicodeString.php | 4 +- src/Symfony/Component/String/ByteString.php | 6 +- .../Component/String/UnicodeString.php | 44 +++++++--- .../Translation/Dumper/FileDumper.php | 2 - .../Validator/Constraints/Length.php | 2 +- .../Mapping/Loader/YamlFileLoader.php | 4 +- .../Service/ServiceSubscriberTraitTest.php | 2 +- 68 files changed, 194 insertions(+), 226 deletions(-) diff --git a/.github/expected-missing-return-types.diff b/.github/expected-missing-return-types.diff index e7b91d8adf01d..ac23e3a413112 100644 --- a/.github/expected-missing-return-types.diff +++ b/.github/expected-missing-return-types.diff @@ -1343,7 +1343,7 @@ diff --git a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php b/src/Symfony/ diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php --- a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php -@@ -71,5 +71,5 @@ class MemcachedAdapter extends AbstractAdapter +@@ -72,5 +72,5 @@ class MemcachedAdapter extends AbstractAdapter * @return bool */ - public static function isSupported() @@ -1353,7 +1353,7 @@ diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symf diff --git a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php --- a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php -@@ -101,5 +101,5 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface +@@ -102,5 +102,5 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface * @throws \DomainException When an unsupported PDO driver is used */ - public function createTable() @@ -1505,7 +1505,7 @@ diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/ + protected function doUnlink(string $file): bool { return @unlink($file); -@@ -175,5 +175,5 @@ trait FilesystemCommonTrait +@@ -167,5 +167,5 @@ trait FilesystemCommonTrait * @return void */ - public function __wakeup() @@ -7313,14 +7313,14 @@ diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Comp - public function setMethod(string $method) + public function setMethod(string $method): void { - $this->method = null; + unset($this->method); @@ -1301,5 +1301,5 @@ class Request * @return void */ - public function setFormat(?string $format, string|array $mimeTypes) + public function setFormat(?string $format, string|array $mimeTypes): void { - if (null === static::$formats) { + if (!isset(static::$formats)) { @@ -1333,5 +1333,5 @@ class Request * @return void */ @@ -7342,14 +7342,14 @@ diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Comp + public function setLocale(string $locale): void { $this->setPhpDefaultLocale($this->locale = $locale); -@@ -1756,5 +1756,5 @@ class Request +@@ -1744,5 +1744,5 @@ class Request * @return string */ - protected function prepareRequestUri() + protected function prepareRequestUri(): string { $requestUri = ''; -@@ -1927,5 +1927,5 @@ class Request +@@ -1915,5 +1915,5 @@ class Request * @return void */ - protected static function initializeFormats() @@ -11059,14 +11059,14 @@ diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusExceptio diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php -@@ -43,5 +43,5 @@ class AuthenticationException extends RuntimeException +@@ -34,5 +34,5 @@ class AuthenticationException extends RuntimeException * @return void */ - public function setToken(TokenInterface $token) + public function setToken(TokenInterface $token): void { $this->token = $token; -@@ -94,5 +94,5 @@ class AuthenticationException extends RuntimeException +@@ -85,5 +85,5 @@ class AuthenticationException extends RuntimeException * @return string */ - public function getMessageKey() @@ -11778,7 +11778,7 @@ diff --git a/src/Symfony/Component/String/Slugger/AsciiSlugger.php b/src/Symfony diff --git a/src/Symfony/Component/String/UnicodeString.php b/src/Symfony/Component/String/UnicodeString.php --- a/src/Symfony/Component/String/UnicodeString.php +++ b/src/Symfony/Component/String/UnicodeString.php -@@ -342,5 +342,5 @@ class UnicodeString extends AbstractUnicodeString +@@ -366,5 +366,5 @@ class UnicodeString extends AbstractUnicodeString * @return void */ - public function __wakeup() @@ -12075,14 +12075,14 @@ diff --git a/src/Symfony/Component/Translation/Dumper/DumperInterface.php b/src/ diff --git a/src/Symfony/Component/Translation/Dumper/FileDumper.php b/src/Symfony/Component/Translation/Dumper/FileDumper.php --- a/src/Symfony/Component/Translation/Dumper/FileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/FileDumper.php -@@ -40,5 +40,5 @@ abstract class FileDumper implements DumperInterface +@@ -38,5 +38,5 @@ abstract class FileDumper implements DumperInterface * @return void */ - public function setRelativePathTemplate(string $relativePathTemplate) + public function setRelativePathTemplate(string $relativePathTemplate): void { $this->relativePathTemplate = $relativePathTemplate; -@@ -48,5 +48,5 @@ abstract class FileDumper implements DumperInterface +@@ -46,5 +46,5 @@ abstract class FileDumper implements DumperInterface * @return void */ - public function dump(MessageCatalogue $messages, array $options = []) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 13e155235358b..4590b5a18bd93 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -44,7 +44,6 @@ use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener; use Symfony\Component\WebLink\GenericLinkProvider; use Symfony\Component\WebLink\HttpHeaderSerializer; -use Symfony\Component\WebLink\Link; use Symfony\Contracts\Service\Attribute\Required; use Symfony\Contracts\Service\ServiceSubscriberInterface; use Twig\Environment; @@ -64,7 +63,7 @@ abstract class AbstractController implements ServiceSubscriberInterface #[Required] public function setContainer(ContainerInterface $container): ?ContainerInterface { - $previous = $this->container; + $previous = $this->container ?? null; $this->container = $container; return $previous; diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index f9747a3c489a8..3db6519d2db54 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -61,7 +61,7 @@ public function __construct(ContainerInterface $container, mixed $resource, arra public function getRouteCollection(): RouteCollection { - if (null === $this->collection) { + if (!isset($this->collection)) { $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']); $this->resolveParameters($this->collection); $this->collection->addResource(new ContainerParametersResource($this->collectedParameters)); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php index 04e419cd82d6b..98c57c091b296 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AccessTokenFactory.php @@ -68,19 +68,19 @@ public function addConfiguration(NodeDefinition $node): void ->beforeNormalization() ->ifString() - ->then(static function (string $v): array { return ['id' => $v]; }) + ->then(static fn ($v) => ['id' => $v]) ->end() ->beforeNormalization() - ->ifTrue(static function ($v) { return \is_array($v) && 1 < \count($v); }) - ->then(static function () { throw new InvalidConfigurationException('You cannot configure multiple token handlers.'); }) + ->ifTrue(static fn ($v) => \is_array($v) && 1 < \count($v)) + ->then(static fn () => throw new InvalidConfigurationException('You cannot configure multiple token handlers.')) ->end() // "isRequired" must be set otherwise the following custom validation is not called ->isRequired() ->beforeNormalization() - ->ifTrue(static function ($v) { return \is_array($v) && !$v; }) - ->then(static function () { throw new InvalidConfigurationException('You must set a token handler.'); }) + ->ifTrue(static fn ($v) => \is_array($v) && !$v) + ->then(static fn () => throw new InvalidConfigurationException('You must set a token handler.')) ->end() ->children() diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index 67579e3812de5..ed9bf8e8bdd1d 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -61,11 +61,11 @@ class Cookie public function __construct(string $name, ?string $value, string $expires = null, string $path = null, string $domain = '', bool $secure = false, bool $httponly = true, bool $encodedValue = false, string $samesite = null) { if ($encodedValue) { - $this->value = urldecode($value); - $this->rawValue = $value; + $this->rawValue = $value ?? ''; + $this->value = urldecode($this->rawValue); } else { - $this->value = $value; - $this->rawValue = rawurlencode($value ?? ''); + $this->value = $value ?? ''; + $this->rawValue = rawurlencode($this->value); } $this->name = $name; $this->path = empty($path) ? '/' : $path; diff --git a/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php b/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php index 12d6db86a1515..f8cb92dbf2fa2 100644 --- a/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php @@ -64,7 +64,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $ser throw new CacheException('Couchbase >= 2.6.0 < 3.0.0 is required.'); } - set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); }); + set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line)); $dsnPattern = '/^(?couchbase(?:s)?)\:\/\/(?:(?[^\:]+)\:(?[^\@]{6,})@)?' .'(?[^\:]+(?:\:\d+)?)(?:\/(?[^\?]+))(?:\?(?.*))?$/i'; diff --git a/src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php b/src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php index 19c9e075db95b..aaa8bbdaef593 100644 --- a/src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/CouchbaseCollectionAdapter.php @@ -57,7 +57,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $dsn throw new CacheException('Couchbase >= 3.0.0 < 4.0.0 is required.'); } - set_error_handler(function ($type, $msg, $file, $line): bool { throw new \ErrorException($msg, 0, $type, $file, $line); }); + set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line)); $dsnPattern = '/^(?couchbase(?:s)?)\:\/\/(?:(?[^\:]+)\:(?[^\@]{6,})@)?' .'(?[^\:]+(?:\:\d+)?)(?:\/(?[^\/\?]+))(?:(?:\/(?[^\/]+))' diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php index 3843af125c1b1..8c4abfa6a38eb 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php @@ -29,7 +29,7 @@ class DoctrineDbalAdapter extends AbstractAdapter implements PruneableInterface { - protected $maxIdLength = 255; + private const MAX_KEY_LENGTH = 255; private MarshallerInterface $marshaller; private Connection $conn; @@ -94,6 +94,7 @@ public function __construct(Connection|string $connOrDsn, string $namespace = '' $this->conn = DriverManager::getConnection($params, $config); } + $this->maxIdLength = self::MAX_KEY_LENGTH; $this->table = $options['db_table'] ?? $this->table; $this->idCol = $options['db_id_col'] ?? $this->idCol; $this->dataCol = $options['db_data_col'] ?? $this->dataCol; diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php index 054f6d19576e6..23fc94d453561 100644 --- a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php @@ -29,8 +29,7 @@ class MemcachedAdapter extends AbstractAdapter */ private const RESERVED_MEMCACHED = " \n\r\t\v\f\0"; private const RESERVED_PSR6 = '@()\{}/'; - - protected $maxIdLength = 250; + private const MAX_KEY_LENGTH = 250; private MarshallerInterface $marshaller; private \Memcached $client; @@ -51,6 +50,8 @@ public function __construct(\Memcached $client, string $namespace = '', int $def if (!static::isSupported()) { throw new CacheException('Memcached > 3.1.5 is required.'); } + $this->maxIdLength = self::MAX_KEY_LENGTH; + if ('Memcached' === $client::class) { $opt = $client->getOption(\Memcached::OPT_SERIALIZER); if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) { @@ -96,7 +97,7 @@ public static function createConnection(#[\SensitiveParameter] array|string $ser if (!static::isSupported()) { throw new CacheException('Memcached > 3.1.5 is required.'); } - set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); }); + set_error_handler(static fn ($type, $msg, $file, $line) => throw new \ErrorException($msg, 0, $type, $file, $line)); try { $client = new \Memcached($options['persistent_id'] ?? null); $username = $options['username'] ?? null; diff --git a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php index dfffb3bd13586..29df2563c9ad0 100644 --- a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php @@ -19,7 +19,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface { - protected $maxIdLength = 255; + private const MAX_KEY_LENGTH = 255; private MarshallerInterface $marshaller; private \PDO|Connection $conn; @@ -75,6 +75,7 @@ public function __construct(#[\SensitiveParameter] \PDO|string $connOrDsn, strin $this->dsn = $connOrDsn; } + $this->maxIdLength = self::MAX_KEY_LENGTH; $this->table = $options['db_table'] ?? $this->table; $this->idCol = $options['db_id_col'] ?? $this->idCol; $this->dataCol = $options['db_data_col'] ?? $this->dataCol; diff --git a/src/Symfony/Component/Cache/LockRegistry.php b/src/Symfony/Component/Cache/LockRegistry.php index 888dd6f5f2e7c..4b750cb44eeac 100644 --- a/src/Symfony/Component/Cache/LockRegistry.php +++ b/src/Symfony/Component/Cache/LockRegistry.php @@ -97,7 +97,7 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s } self::$signalingException ??= unserialize("O:9:\"Exception\":1:{s:16:\"\0Exception\0trace\";a:0:{}}"); - self::$signalingCallback ??= function () { throw self::$signalingException; }; + self::$signalingCallback ??= fn () => throw self::$signalingException; while (true) { try { diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php index 9c5f732ffca29..d16e5bb8652c8 100644 --- a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php +++ b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php @@ -87,7 +87,7 @@ protected function doUnlink(string $file) private function write(string $file, string $data, int $expiresAt = null): bool { - set_error_handler(self::throwError(...)); + set_error_handler(static fn ($type, $message, $file, $line) => throw new \ErrorException($message, 0, $type, $file, $line)); try { $tmp = $this->directory.$this->tmpSuffix ??= str_replace('/', '-', base64_encode(random_bytes(6))); try { @@ -158,14 +158,6 @@ private function scanHashDir(string $directory): \Generator } } - /** - * @internal - */ - public static function throwError(int $type, string $message, string $file, int $line): never - { - throw new \ErrorException($message, 0, $type, $file, $line); - } - public function __sleep(): array { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index 0110f0502f5cf..3ada5c5503405 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -348,7 +348,7 @@ protected function getNodeBuilder(): NodeBuilder protected function createNode(): NodeInterface { - if (null === $this->prototype) { + if (!isset($this->prototype)) { $node = new ArrayNode($this->name, $this->parent, $this->pathSeparator); $this->validateConcreteNode($node); @@ -382,7 +382,7 @@ protected function createNode(): NodeInterface if (false !== $this->addDefaultChildren) { $node->setAddChildrenIfNoneSet($this->addDefaultChildren); - if ($this->prototype instanceof static && null === $this->prototype->prototype) { + if ($this->prototype instanceof static && !isset($this->prototype->prototype)) { $this->prototype->addDefaultsIfNotSet(); } } @@ -404,18 +404,18 @@ protected function createNode(): NodeInterface $node->setDeprecated($this->deprecation['package'], $this->deprecation['version'], $this->deprecation['message']); } - if (null !== $this->normalization) { + if (isset($this->normalization)) { $node->setNormalizationClosures($this->normalization->before); $node->setNormalizedTypes($this->normalization->declaredTypes); $node->setXmlRemappings($this->normalization->remappings); } - if (null !== $this->merge) { + if (isset($this->merge)) { $node->setAllowOverwrite($this->merge->allowOverwrite); $node->setAllowFalse($this->merge->allowFalse); } - if (null !== $this->validation) { + if (isset($this->validation)) { $node->setFinalValidationClosures($this->validation->rules); } diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php index 1cd32ca3eeaf8..2defcfe64b9b4 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php @@ -105,7 +105,7 @@ public function getNode(bool $forceRootNode = false): NodeInterface $this->parent = null; } - if (null !== $this->normalization) { + if (isset($this->normalization)) { $allowedTypes = []; foreach ($this->normalization->before as $expr) { $allowedTypes[] = $expr->allowedTypes; @@ -115,7 +115,7 @@ public function getNode(bool $forceRootNode = false): NodeInterface $this->normalization->declaredTypes = $allowedTypes; } - if (null !== $this->validation) { + if (isset($this->validation)) { $this->validation->rules = ExprBuilder::buildExpressions($this->validation->rules); } diff --git a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php index 621e2a07a1e42..3e79eb4da514e 100644 --- a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php @@ -53,7 +53,7 @@ public function buildTree(): NodeInterface public function setPathSeparator(string $separator) { // unset last built as changing path separator changes all nodes - $this->tree = null; + unset($this->tree); $this->root->setPathSeparator($separator); } diff --git a/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php index c49391f44473e..a4cc53a55247e 100644 --- a/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php @@ -33,11 +33,11 @@ protected function createNode(): NodeInterface { $node = $this->instantiateNode(); - if (null !== $this->normalization) { + if (isset($this->normalization)) { $node->setNormalizationClosures($this->normalization->before); } - if (null !== $this->merge) { + if (isset($this->merge)) { $node->setAllowOverwrite($this->merge->allowOverwrite); } @@ -55,7 +55,7 @@ protected function createNode(): NodeInterface $node->setDeprecated($this->deprecation['package'], $this->deprecation['version'], $this->deprecation['message']); } - if (null !== $this->validation) { + if (isset($this->validation)) { $node->setFinalValidationClosures($this->validation->rules); } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php index 6876e4456df9e..873ffb4051e96 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php @@ -198,7 +198,7 @@ public function testEndThenPartNotSpecified() $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('You must specify a then part.'); $builder = $this->getTestBuilder(); - $builder->ifPart = 'test'; + $builder->ifPart = static fn () => false; $builder->end(); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index 51076036dc4ff..b4fd75f7ef884 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -561,7 +561,7 @@ private function set(string $type, string $id): void private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): \Closure { - if (null === $this->typesClone->container) { + if (!isset($this->typesClone->container)) { $this->typesClone->container = new ContainerBuilder($this->container->getParameterBag()); $this->typesClone->container->setAliases($this->container->getAliases()); $this->typesClone->container->setDefinitions($this->container->getDefinitions()); diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 38270e16b0e38..92949d55f1f01 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -1639,7 +1639,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php index fa44784cafd32..a2aa853876ffc 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php @@ -27,7 +27,7 @@ abstract class AbstractConfigurator public const FACTORY = 'unknown'; /** - * @var callable(mixed, bool)|null + * @var \Closure(mixed, bool):mixed|null */ public static $valuePreProcessor; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 95bf7aa4df39f..fd6247173be07 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -72,7 +72,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index be77a31954e4b..78b1bcc7d791f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -72,7 +72,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php index 03cb9b5ba5ee5..fea6ba5660fa7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php @@ -87,7 +87,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php index c434b19d9d2fe..d6c3466a7f88c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services26.php @@ -83,7 +83,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index 65aded752be4e..3d5619f7b3e1e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt index c3fddf9e67175..0b367ccb4456e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt @@ -678,7 +678,7 @@ class ProjectServiceContainer extends Container public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 8161543a7d715..f0bfa8855a7ef 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -462,7 +462,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt index 4fcb352ade2cc..7ef2e555a4522 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt @@ -521,7 +521,7 @@ class ProjectServiceContainer extends Container public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt index cc147d95abe10..07dd32230637d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt @@ -114,7 +114,7 @@ class ProjectServiceContainer extends Container public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php index 97979327b7e9b..c687dde461168 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php @@ -76,7 +76,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_base64_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_base64_env.php index 021599934834c..82e18441cf149 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_base64_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_base64_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_csv_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_csv_env.php index 2a48fdb329cc4..56ac58165433e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_csv_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_csv_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_default_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_default_env.php index 292f0d6fed825..812bd98596283 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_default_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_default_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters.php index 90a79cba63a2a..036dd7f0d6d07 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters.php @@ -80,7 +80,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt index 98476a4c1a171..a16e843217caa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deprecated_parameters_as_files.txt @@ -124,7 +124,7 @@ class ProjectServiceContainer extends Container public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php index 589d2e81f04b2..7ed086a12e04f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php @@ -91,7 +91,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php index 7433eed182639..cc6e8cd889514 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php @@ -462,7 +462,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_json_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_json_env.php index 2fd5aa4c3a958..87d5a1650b71b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_json_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_json_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_query_string_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_query_string_env.php index 1a04af65f30e0..bf5eeedf5c64c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_query_string_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_query_string_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php index 556e91d783c31..a092759862e15 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php @@ -95,7 +95,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_unsupported_characters.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_unsupported_characters.php index 2849c8b53f04f..9d6eeb20e3916 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_unsupported_characters.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_unsupported_characters.php @@ -94,7 +94,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_url_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_url_env.php index 7f0fb1d9d4af6..90426868f2279 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_url_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_url_env.php @@ -59,7 +59,7 @@ public function setParameter(string $name, $value): void public function getParameterBag(): ParameterBagInterface { - if (null === $this->parameterBag) { + if (!isset($this->parameterBag)) { $parameters = $this->parameters; foreach ($this->loadedDynamicParameters as $name => $loaded) { $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 274aeee5fc803..27d8166dfb497 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1110,7 +1110,7 @@ private function parseXhtml(string $htmlContent, string $charset = 'UTF-8'): \DO */ private function convertToHtmlEntities(string $htmlContent, string $charset = 'UTF-8'): string { - set_error_handler(function () { throw new \Exception(); }); + set_error_handler(static fn () => throw new \Exception()); try { return mb_encode_numericentity($htmlContent, [0x80, 0x10FFFF, 0, 0x1FFFFF], $charset); diff --git a/src/Symfony/Component/ErrorHandler/ErrorHandler.php b/src/Symfony/Component/ErrorHandler/ErrorHandler.php index e04d5b0002681..5a8394fb32acb 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorHandler.php +++ b/src/Symfony/Component/ErrorHandler/ErrorHandler.php @@ -359,7 +359,7 @@ public function screamAt(int $levels, bool $replace = false): int private function reRegister(int $prev): void { if ($prev !== ($this->thrownErrors | $this->loggedErrors)) { - $handler = set_error_handler('is_int'); + $handler = set_error_handler(static fn () => null); $handler = \is_array($handler) ? $handler[0] : null; restore_error_handler(); if ($handler === $this) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php index f4885ec4eb407..1a5fe113b423e 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php @@ -56,7 +56,7 @@ public function testStopwatchEventIsStoppedWhenListenerThrows() $dispatcher = $this->createStub(EventDispatcherInterface::class); - $wrappedListener = new WrappedListener(function () { throw new \Exception(); }, null, $stopwatch, $dispatcher); + $wrappedListener = new WrappedListener(static fn () => throw new \Exception(), null, $stopwatch, $dispatcher); try { $wrappedListener(new \stdClass(), 'foo', $dispatcher); diff --git a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php index 48331167bd275..0cacfc6067a40 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php @@ -55,7 +55,7 @@ public function compile(Compiler $compiler): void } $compiler - ->raw('(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(') + ->raw('(static function ($regexp, $str) { set_error_handler(static fn ($t, $m) => throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12))); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })(') ->compile($this->nodes['right']) ->raw(', ') ->compile($this->nodes['left']) @@ -194,9 +194,7 @@ public static function inArray($value, array $array): bool private function evaluateMatches(string $regexp, ?string $str): int { - set_error_handler(function ($t, $m) use ($regexp) { - throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12)); - }); + set_error_handler(static fn ($t, $m) => throw new SyntaxError(sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12))); try { return preg_match($regexp, (string) $str); } finally { diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php index 610c6b0dd289b..a188b3e066e7a 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php @@ -123,7 +123,7 @@ public static function getCompileData(): array ['range(1, 3)', new BinaryNode('..', new ConstantNode(1), new ConstantNode(3))], - ['(static function ($regexp, $str) { set_error_handler(function ($t, $m) use ($regexp, $str) { throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12)); }); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))], + ['(static function ($regexp, $str) { set_error_handler(static fn ($t, $m) => throw new \Symfony\Component\ExpressionLanguage\SyntaxError(sprintf(\'Regexp "%s" passed to "matches" is not valid\', $regexp).substr($m, 12))); try { return preg_match($regexp, (string) $str); } finally { restore_error_handler(); } })("/^[a-z]+\$/", "abc")', new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('/^[a-z]+$/'))], ['str_starts_with("abc", "a")', new BinaryNode('starts with', new ConstantNode('abc'), new ConstantNode('a'))], ['str_ends_with("abc", "a")', new BinaryNode('ends with', new ConstantNode('abc'), new ConstantNode('a'))], diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 2af19b0bf86b9..4ac7e55fba2a6 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -69,7 +69,7 @@ public function __construct(iterable $choices, callable $value = null) if (null !== $value) { // If a deterministic value generator was passed, use it later - $this->valueCallback = $value; + $this->valueCallback = $value(...); } else { // Otherwise generate incrementing integers as values $value = static function () { diff --git a/src/Symfony/Component/Form/Test/TypeTestCase.php b/src/Symfony/Component/Form/Test/TypeTestCase.php index a925c555ec05d..ac8eb9baa47ec 100644 --- a/src/Symfony/Component/Form/Test/TypeTestCase.php +++ b/src/Symfony/Component/Form/Test/TypeTestCase.php @@ -35,13 +35,6 @@ protected function setUp(): void $this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory); } - protected function tearDown(): void - { - if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) { - $this->validator = null; - } - } - protected function getExtensions() { $extensions = []; diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index 180a9578fe488..e26d31299c389 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -264,8 +264,8 @@ public function testDontValidateIfNotSynchronized() ]) ->setData($object) ->addViewTransformer(new CallbackTransformer( - fn ($data) => $data, - function () { throw new TransformationFailedException(); } + static fn ($data) => $data, + static fn () => throw new TransformationFailedException() )) ->getForm(); @@ -301,8 +301,8 @@ public function testAddInvalidErrorEvenIfNoValidationGroups() ]) ->setData($object) ->addViewTransformer(new CallbackTransformer( - fn ($data) => $data, - function () { throw new TransformationFailedException(); } + static fn ($data) => $data, + static fn () => throw new TransformationFailedException() )) ->getForm(); @@ -336,8 +336,8 @@ public function testDontValidateConstraintsIfNotSynchronized() $form = $this->getBuilder('name', '\stdClass', $options) ->setData($object) ->addViewTransformer(new CallbackTransformer( - fn ($data) => $data, - function () { throw new TransformationFailedException(); } + static fn ($data) => $data, + static fn () => throw new TransformationFailedException() )) ->getForm(); @@ -367,8 +367,8 @@ public function testTransformationFailedExceptionInvalidMessageIsUsed() ]) ->setData($object) ->addViewTransformer(new CallbackTransformer( - fn ($data) => $data, - function () { + static fn ($data) => $data, + static function () { $failure = new TransformationFailedException(); $failure->setInvalidMessage('safe message to be used', ['{{ bar }}' => 'bar']); diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php index 6cb270ac2e077..93ad47b19635e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php @@ -72,8 +72,8 @@ protected function getForm($name = 'name', $propertyPath = null, $dataClass = nu if (!$synchronized) { $config->addViewTransformer(new CallbackTransformer( - fn ($normData) => $normData, - function () { throw new TransformationFailedException(); } + static fn ($normData) => $normData, + static fn () => throw new TransformationFailedException() )); } diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 71e806fc15341..ca18c92f13f97 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -293,7 +293,7 @@ public function sendContent(): static { try { if (!$this->isSuccessful()) { - return parent::sendContent(); + return $this; } if (0 === $this->maxlen) { diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 776449c867309..285e4db79f037 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -279,16 +279,16 @@ public function initialize(array $query = [], array $request = [], array $attrib $this->headers = new HeaderBag($this->server->getHeaders()); $this->content = $content; - $this->languages = null; - $this->charsets = null; - $this->encodings = null; - $this->acceptableContentTypes = null; - $this->pathInfo = null; - $this->requestUri = null; - $this->baseUrl = null; - $this->basePath = null; - $this->method = null; - $this->format = null; + unset($this->languages); + unset($this->charsets); + unset($this->encodings); + unset($this->acceptableContentTypes); + unset($this->pathInfo); + unset($this->requestUri); + unset($this->baseUrl); + unset($this->basePath); + unset($this->method); + unset($this->format); } /** @@ -465,16 +465,16 @@ public function duplicate(array $query = null, array $request = null, array $att $dup->server = new ServerBag($server); $dup->headers = new HeaderBag($dup->server->getHeaders()); } - $dup->languages = null; - $dup->charsets = null; - $dup->encodings = null; - $dup->acceptableContentTypes = null; - $dup->pathInfo = null; - $dup->requestUri = null; - $dup->baseUrl = null; - $dup->basePath = null; - $dup->method = null; - $dup->format = null; + unset($dup->languages); + unset($dup->charsets); + unset($dup->encodings); + unset($dup->acceptableContentTypes); + unset($dup->pathInfo); + unset($dup->requestUri); + unset($dup->baseUrl); + unset($dup->basePath); + unset($dup->method); + unset($dup->format); if (!$dup->get('_format') && $this->get('_format')) { $dup->attributes->set('_format', $this->get('_format')); @@ -1179,7 +1179,7 @@ public function getHost(): string */ public function setMethod(string $method) { - $this->method = null; + unset($this->method); $this->server->set('REQUEST_METHOD', $method); } @@ -1198,7 +1198,7 @@ public function setMethod(string $method) */ public function getMethod(): string { - if (null !== $this->method) { + if (isset($this->method)) { return $this->method; } @@ -1246,7 +1246,7 @@ public function getRealMethod(): string */ public function getMimeType(string $format): ?string { - if (null === static::$formats) { + if (!isset(static::$formats)) { static::initializeFormats(); } @@ -1260,7 +1260,7 @@ public function getMimeType(string $format): ?string */ public static function getMimeTypes(string $format): array { - if (null === static::$formats) { + if (!isset(static::$formats)) { static::initializeFormats(); } @@ -1277,7 +1277,7 @@ public function getFormat(?string $mimeType): ?string $canonicalMimeType = trim(substr($mimeType, 0, $pos)); } - if (null === static::$formats) { + if (!isset(static::$formats)) { static::initializeFormats(); } @@ -1302,7 +1302,7 @@ public function getFormat(?string $mimeType): ?string */ public function setFormat(?string $format, string|array $mimeTypes) { - if (null === static::$formats) { + if (!isset(static::$formats)) { static::initializeFormats(); } @@ -1583,13 +1583,13 @@ public function isNoCache(): bool */ public function getPreferredFormat(?string $default = 'html'): ?string { - if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) { - return $this->preferredFormat; + if (isset($this->preferredFormat) || null !== $preferredFormat = $this->getRequestFormat(null)) { + return $this->preferredFormat ??= $preferredFormat; } foreach ($this->getAcceptableContentTypes() as $mimeType) { - if ($this->preferredFormat = $this->getFormat($mimeType)) { - return $this->preferredFormat; + if ($preferredFormat = $this->getFormat($mimeType)) { + return $this->preferredFormat = $preferredFormat; } } @@ -1636,7 +1636,7 @@ public function getPreferredLanguage(array $locales = null): ?string */ public function getLanguages(): array { - if (null !== $this->languages) { + if (isset($this->languages)) { return $this->languages; } @@ -1677,11 +1677,7 @@ public function getLanguages(): array */ public function getCharsets(): array { - if (null !== $this->charsets) { - return $this->charsets; - } - - return $this->charsets = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all())); + return $this->charsets ??= array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all())); } /** @@ -1691,11 +1687,7 @@ public function getCharsets(): array */ public function getEncodings(): array { - if (null !== $this->encodings) { - return $this->encodings; - } - - return $this->encodings = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all())); + return $this->encodings ??= array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all())); } /** @@ -1705,11 +1697,7 @@ public function getEncodings(): array */ public function getAcceptableContentTypes(): array { - if (null !== $this->acceptableContentTypes) { - return $this->acceptableContentTypes; - } - - return $this->acceptableContentTypes = array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all())); + return $this->acceptableContentTypes ??= array_map('strval', array_keys(AcceptHeader::fromString($this->headers->get('Accept'))->all())); } /** diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index 2c8ff15f3650e..7f54783ecae12 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -51,7 +51,7 @@ public function __construct(callable $callback = null, int $status = 200, array */ public function setCallback(callable $callback): static { - $this->callback = $callback; + $this->callback = $callback(...); return $this; } @@ -90,8 +90,8 @@ public function sendContent(): static $this->streamed = true; - if (null === $this->callback) { - throw new \LogicException('The Response callback must not be null.'); + if (!isset($this->callback)) { + throw new \LogicException('The Response callback must be set.'); } ($this->callback)(); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index a5a240a6265ec..8ac5b7f1e1307 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -40,7 +40,7 @@ class HttpKernelTest extends TestCase public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() { $this->expectException(\RuntimeException::class); - $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); + $kernel = $this->getHttpKernel(new EventDispatcher(), static fn () => throw new \RuntimeException()); $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); } @@ -48,7 +48,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsTrue() { $requestStack = new RequestStack(); - $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack); + $kernel = $this->getHttpKernel(new EventDispatcher(), static fn () => throw new \RuntimeException(), $requestStack); try { $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); @@ -61,7 +61,7 @@ public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCat public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsFalse() { $requestStack = new RequestStack(); - $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }, $requestStack); + $kernel = $this->getHttpKernel(new EventDispatcher(), static fn () => throw new \RuntimeException(), $requestStack); try { $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false); @@ -74,7 +74,7 @@ public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCat public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable() { $requestStack = new RequestStack(); - $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \Error(); }, $requestStack); + $kernel = $this->getHttpKernel(new EventDispatcher(), static fn () => throw new \Error(), $requestStack); try { $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); @@ -92,7 +92,7 @@ public function testRequestStackIsNotBrokenWhenControllerThrowsAnThrowable() public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered() { $this->expectException(\RuntimeException::class); - $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); + $kernel = $this->getHttpKernel(new EventDispatcher(), static fn () => throw new \RuntimeException()); $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, false); } @@ -109,7 +109,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHand $event->setResponse(new Response($event->getThrowable()->getMessage())); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new \RuntimeException('foo'); }); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new \RuntimeException('foo')); $response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); $this->assertEquals('500', $response->getStatusCode()); @@ -128,7 +128,7 @@ public function testHandleWhenControllerThrowsAThrowableAndCatchIsTrueWithAHandl $event->setResponse(new Response($event->getThrowable()->getMessage())); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new \TypeError('foo'); }, handleAllThrowables: true); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new \TypeError('foo'), handleAllThrowables: true); $response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); $this->assertEquals('500', $response->getStatusCode()); @@ -147,7 +147,7 @@ public function testHandleWhenControllerThrowsAThrowableAndCatchIsFalseWithAHand $event->setResponse(new Response($event->getThrowable()->getMessage())); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new \TypeError('foo'); }, handleAllThrowables: true); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new \TypeError('foo'), handleAllThrowables: true); $this->expectException(\TypeError::class); $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, false); } @@ -168,7 +168,7 @@ public function testHandleWhenControllerThrowsAThrowableAndCatchIsTrueNotHandlin $controllerResolver ->expects($this->any()) ->method('getController') - ->willReturn(function () { throw new \TypeError('foo'); }); + ->willReturn(static fn () => throw new \TypeError('foo')); $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver @@ -196,7 +196,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithANonH // should set a response, but does not }); - $kernel = $this->getHttpKernel($dispatcher, function () use ($exception) { throw $exception; }); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw $exception); try { $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); @@ -213,7 +213,7 @@ public function testHandleExceptionWithARedirectionResponse() $event->setResponse(new RedirectResponse('/login', 301)); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new AccessDeniedHttpException(); }); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new AccessDeniedHttpException()); $response = $kernel->handle(new Request()); $this->assertEquals('301', $response->getStatusCode()); @@ -227,7 +227,7 @@ public function testHandleHttpException() $event->setResponse(new Response($event->getThrowable()->getMessage())); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new MethodNotAllowedHttpException(['POST']); }); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new MethodNotAllowedHttpException(['POST'])); $response = $kernel->handle(new Request()); $this->assertEquals('405', $response->getStatusCode()); @@ -255,7 +255,7 @@ public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($expec $event->setResponse(new Response('', $expectedStatusCode)); }); - $kernel = $this->getHttpKernel($dispatcher, function () { throw new \RuntimeException(); }); + $kernel = $this->getHttpKernel($dispatcher, static fn () => throw new \RuntimeException()); $response = $kernel->handle(new Request()); $this->assertEquals($expectedStatusCode, $response->getStatusCode()); @@ -335,7 +335,7 @@ public function testHandleWhenTheControllerIsAStaticArray() public function testHandleWhenTheControllerDoesNotReturnAResponse() { $dispatcher = new EventDispatcher(); - $kernel = $this->getHttpKernel($dispatcher, function () {}); + $kernel = $this->getHttpKernel($dispatcher, static fn () => null); try { $kernel->handle(new Request()); diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index e3c3a6d4592ae..24a610b242cc7 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -46,7 +46,6 @@ public function __wakeup() public function __destruct() { $con = $this->connection->getResource(); - $this->connection = null; if (!isset($this->results)) { return; @@ -60,7 +59,6 @@ public function __destruct() throw new LdapException('Could not free results: '.ldap_error($con)); } } - unset($this->results); } public function execute(): CollectionInterface diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php index 50c29e44b8ece..a7639cd4cec6c 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherDumper.php @@ -349,7 +349,7 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo $state->markTail = 0; // if the regex is too large, throw a signaling exception to recompute with smaller chunk size - set_error_handler(function ($type, $message) { throw str_contains($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message); }); + set_error_handler(fn ($type, $message) => throw str_contains($message, $this->signalingException->getMessage()) ? $this->signalingException : new \ErrorException($message)); try { preg_match($state->regex, ''); } finally { diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 3fa13457b2112..045a035a2f04a 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -193,10 +193,10 @@ public function setContext(RequestContext $context) { $this->context = $context; - if (null !== $this->matcher) { + if (isset($this->matcher)) { $this->getMatcher()->setContext($context); } - if (null !== $this->generator) { + if (isset($this->generator)) { $this->getGenerator()->setContext($context); } } @@ -242,7 +242,7 @@ public function matchRequest(Request $request): array */ public function getMatcher(): UrlMatcherInterface|RequestMatcherInterface { - if (null !== $this->matcher) { + if (isset($this->matcher)) { return $this->matcher; } @@ -283,7 +283,7 @@ function (ConfigCacheInterface $cache) { */ public function getGenerator(): UrlGeneratorInterface { - if (null !== $this->generator) { + if (isset($this->generator)) { return $this->generator; } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index adec6f8758893..a69155e19f3b5 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -23,17 +23,8 @@ #[WithHttpStatus(401)] class AuthenticationException extends RuntimeException { - /** @internal */ - protected $serialized; - private ?TokenInterface $token = null; - public function __construct(string $message = '', int $code = 0, \Throwable $previous = null) - { - unset($this->serialized); - parent::__construct($message, $code, $previous); - } - public function getToken(): ?TokenInterface { return $this->token; @@ -105,23 +96,4 @@ public function getMessageData(): array { return []; } - - /** - * @internal - */ - public function __sleep(): array - { - $this->serialized = $this->__serialize(); - - return ['serialized']; - } - - /** - * @internal - */ - public function __wakeup(): void - { - $this->__unserialize($this->serialized); - unset($this->serialized); - } } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index f17267fc95a6d..a9ca028451826 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -20,6 +20,9 @@ */ class JsonDecode implements DecoderInterface { + /** + * @deprecated since Symfony 6.4, to be removed in 7.0 + */ protected $serializer; /** diff --git a/src/Symfony/Component/String/AbstractString.php b/src/Symfony/Component/String/AbstractString.php index bf491f88d61fe..cc3a2e04c60ad 100644 --- a/src/Symfony/Component/String/AbstractString.php +++ b/src/Symfony/Component/String/AbstractString.php @@ -448,7 +448,7 @@ public function split(string $delimiter, int $limit = null, int $flags = null): $delimiter .= 'i'; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { if (false === $chunks = preg_split($delimiter, $this->string, $limit, $flags)) { @@ -507,7 +507,7 @@ public function toByteString(string $toEncoding = null): ByteString return $b; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { try { diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 32842029dc3e3..df7265f3ebd15 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -228,7 +228,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array $regexp .= 'i'; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { if (false === $match($regexp.'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { @@ -312,7 +312,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static $replace = 'preg_replace'; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { if (null === $string = $replace($fromRegexp.'u', $to, $this->string)) { diff --git a/src/Symfony/Component/String/ByteString.php b/src/Symfony/Component/String/ByteString.php index 212290fed97a0..f5050ddfb8ff4 100644 --- a/src/Symfony/Component/String/ByteString.php +++ b/src/Symfony/Component/String/ByteString.php @@ -236,7 +236,7 @@ public function match(string $regexp, int $flags = 0, int $offset = 0): array $regexp .= 'i'; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { if (false === $match($regexp, $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { @@ -300,7 +300,7 @@ public function replaceMatches(string $fromRegexp, string|callable $to): static $replace = \is_array($to) || $to instanceof \Closure ? 'preg_replace_callback' : 'preg_replace'; - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { if (null === $string = $replace($fromRegexp, $to, $this->string)) { @@ -417,7 +417,7 @@ public function toCodePointString(string $fromEncoding = null): CodePointString return $u; } - set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); }); + set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); try { try { diff --git a/src/Symfony/Component/String/UnicodeString.php b/src/Symfony/Component/String/UnicodeString.php index 851e0870075be..b33e37b715a7e 100644 --- a/src/Symfony/Component/String/UnicodeString.php +++ b/src/Symfony/Component/String/UnicodeString.php @@ -34,23 +34,32 @@ class UnicodeString extends AbstractUnicodeString { public function __construct(string $string = '') { - $this->string = normalizer_is_normalized($string) ? $string : normalizer_normalize($string); + if ('' === $string || normalizer_is_normalized($this->string = $string)) { + return; + } - if (false === $this->string) { + if (false === $string = normalizer_normalize($string)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); } + + $this->string = $string; } public function append(string ...$suffix): static { $str = clone $this; $str->string = $this->string.(1 >= \count($suffix) ? ($suffix[0] ?? '') : implode('', $suffix)); - normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); - if (false === $str->string) { + if (normalizer_is_normalized($str->string)) { + return $str; + } + + if (false === $string = normalizer_normalize($str->string)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); } + $str->string = $string; + return $str; } @@ -209,12 +218,17 @@ public function prepend(string ...$prefix): static { $str = clone $this; $str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)).$this->string; - normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); - if (false === $str->string) { + if (normalizer_is_normalized($str->string)) { + return $str; + } + + if (false === $string = normalizer_normalize($str->string)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); } + $str->string = $string; + return $str; } @@ -235,11 +249,16 @@ public function replace(string $from, string $to): static } $str->string = $result.$tail; - normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); - if (false === $str->string) { + if (normalizer_is_normalized($str->string)) { + return $str; + } + + if (false === $string = normalizer_normalize($str->string)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); } + + $str->string = $string; } return $str; @@ -269,12 +288,17 @@ public function splice(string $replacement, int $start = 0, int $length = null): $start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0; $length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length; $str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647); - normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string); - if (false === $str->string) { + if (normalizer_is_normalized($str->string)) { + return $str; + } + + if (false === $string = normalizer_normalize($str->string)) { throw new InvalidArgumentException('Invalid UTF-8 string.'); } + $str->string = $string; + return $str; } diff --git a/src/Symfony/Component/Translation/Dumper/FileDumper.php b/src/Symfony/Component/Translation/Dumper/FileDumper.php index ed2c278aaf0fd..e30d4770ee01f 100644 --- a/src/Symfony/Component/Translation/Dumper/FileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/FileDumper.php @@ -35,8 +35,6 @@ abstract class FileDumper implements DumperInterface /** * Sets the template for the relative paths to files. * - * @param string $relativePathTemplate A template for the relative paths to files - * * @return void */ public function setRelativePathTemplate(string $relativePathTemplate) diff --git a/src/Symfony/Component/Validator/Constraints/Length.php b/src/Symfony/Component/Validator/Constraints/Length.php index 59360ace13fe1..7f91cdd8c2fe3 100644 --- a/src/Symfony/Component/Validator/Constraints/Length.php +++ b/src/Symfony/Component/Validator/Constraints/Length.php @@ -59,7 +59,7 @@ class Length extends Constraint public $min; public $charset = 'UTF-8'; public $normalizer; - /* @var self::COUNT_* */ + /** @var self::COUNT_* */ public string $countUnit = self::COUNT_CODEPOINTS; /** diff --git a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php index 2bcaf70877f8c..aa30b9542b8d6 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php @@ -43,7 +43,7 @@ public function __construct(string $file) public function loadClassMetadata(ClassMetadata $metadata): bool { - if (null === $this->classes) { + if (!isset($this->classes)) { $this->loadClassesFromYaml(); } @@ -65,7 +65,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool */ public function getMappedClasses(): array { - if (null === $this->classes) { + if (!isset($this->classes)) { $this->loadClassesFromYaml(); } diff --git a/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php b/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php index 3eb4b31940021..ba370265bac85 100644 --- a/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php +++ b/src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php @@ -146,7 +146,7 @@ class ParentTestService2 public function setContainer(ContainerInterface $container) { - $previous = $this->container; + $previous = $this->container ?? null; $this->container = $container; return $previous;