From 73d769ec55ba178ca79ab90bcdd19390b1529f24 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 19 Mar 2024 11:13:26 +0100 Subject: [PATCH] Make more nullable types explicit --- .../Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php | 2 +- .../Tests/Fixtures/ClassWithAnnotatedParameters.php | 4 ++-- src/Symfony/Component/HttpFoundation/ParameterBag.php | 2 +- src/Symfony/Component/Mailer/Transport.php | 6 +++--- .../Messenger/Command/AbstractFailedMessagesCommand.php | 2 +- .../Component/Messenger/Handler/BatchHandlerInterface.php | 2 +- .../Component/Messenger/Retry/RetryStrategyInterface.php | 4 ++-- src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md | 4 ++-- .../Component/Notifier/Bridge/GoogleChat/CHANGELOG.md | 4 ++-- .../Component/Notifier/Bridge/Mattermost/CHANGELOG.md | 4 ++-- .../PropertyInfo/Extractor/ReflectionExtractor.php | 2 +- .../Authentication/AuthenticationTrustResolverInterface.php | 2 +- .../Security/Core/Authorization/AccessDecisionManager.php | 2 +- .../Component/Security/Http/Firewall/ChannelListener.php | 2 +- src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php | 2 +- .../Component/VarDumper/Tests/Caster/StubCasterTest.php | 2 +- .../Component/VarDumper/Tests/Dumper/CliDumperTest.php | 2 +- .../Component/VarDumper/Tests/Dumper/HtmlDumperTest.php | 2 +- .../functions/dump_data_collector_with_spl_array.phpt | 4 ++-- 19 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php index 19a9bdd5125d..c12f1150b698 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/Fixtures/proxy-implem.php @@ -200,7 +200,7 @@ public function __wakeup() { } - public function setProxyInitializer(\Closure $initializer = null)%S + public function setProxyInitializer(%S\Closure $initializer = null)%S { $this->initializer%s = $initializer; } diff --git a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ClassWithAnnotatedParameters.php b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ClassWithAnnotatedParameters.php index 2bac262ddb49..a9cf0dfcb4d2 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ClassWithAnnotatedParameters.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/ClassWithAnnotatedParameters.php @@ -14,14 +14,14 @@ public function fooMethod(string $foo) /** * @param string $bar parameter not implemented yet */ - public function barMethod(/* string $bar = null */) + public function barMethod(/* ?string $bar = null */) { } /** * @param Quz $quz parameter not implemented yet */ - public function quzMethod(/* Quz $quz = null */) + public function quzMethod(/* ?Quz $quz = null */) { } diff --git a/src/Symfony/Component/HttpFoundation/ParameterBag.php b/src/Symfony/Component/HttpFoundation/ParameterBag.php index e1f89d69ea5e..b542292bc8bf 100644 --- a/src/Symfony/Component/HttpFoundation/ParameterBag.php +++ b/src/Symfony/Component/HttpFoundation/ParameterBag.php @@ -39,7 +39,7 @@ public function __construct(array $parameters = []) * * @return array */ - public function all(/* string $key = null */) + public function all(/* ?string $key = null */) { $key = \func_num_args() > 0 ? func_get_arg(0) : null; diff --git a/src/Symfony/Component/Mailer/Transport.php b/src/Symfony/Component/Mailer/Transport.php index ab7b67e4669a..294442e9261a 100644 --- a/src/Symfony/Component/Mailer/Transport.php +++ b/src/Symfony/Component/Mailer/Transport.php @@ -63,7 +63,7 @@ class Transport * @param HttpClientInterface|null $client * @param LoggerInterface|null $logger */ - public static function fromDsn(string $dsn/* , EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null */): TransportInterface + public static function fromDsn(string $dsn/* , ?EventDispatcherInterface $dispatcher = null, ?HttpClientInterface $client = null, ?LoggerInterface $logger = null */): TransportInterface { $dispatcher = 2 <= \func_num_args() ? func_get_arg(1) : null; $client = 3 <= \func_num_args() ? func_get_arg(2) : null; @@ -79,7 +79,7 @@ public static function fromDsn(string $dsn/* , EventDispatcherInterface $dispatc * @param HttpClientInterface|null $client * @param LoggerInterface|null $logger */ - public static function fromDsns(array $dsns/* , EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null */): TransportInterface + public static function fromDsns(array $dsns/* , ?EventDispatcherInterface $dispatcher = null, ?HttpClientInterface $client = null, ?LoggerInterface $logger = null */): TransportInterface { $dispatcher = 2 <= \func_num_args() ? func_get_arg(1) : null; $client = 3 <= \func_num_args() ? func_get_arg(2) : null; @@ -183,7 +183,7 @@ public function fromDsnObject(Dsn $dsn): TransportInterface * * @return \Traversable */ - public static function getDefaultFactories(/* EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null */): iterable + public static function getDefaultFactories(/* ?EventDispatcherInterface $dispatcher = null, ?HttpClientInterface $client = null, ?LoggerInterface $logger = null */): iterable { $dispatcher = 1 <= \func_num_args() ? func_get_arg(0) : null; $client = 2 <= \func_num_args() ? func_get_arg(1) : null; diff --git a/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php b/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php index 7a6fc212a48a..43ad833728d3 100644 --- a/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php @@ -185,7 +185,7 @@ protected function printPendingMessagesMessage(ReceiverInterface $receiver, Symf /** * @param string|null $name */ - protected function getReceiver(/* string $name = null */): ReceiverInterface + protected function getReceiver(/* ?string $name = null */): ReceiverInterface { if (1 > \func_num_args() && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) { trigger_deprecation('symfony/messenger', '5.3', 'The "%s()" method will have a new "string $name" argument in version 6.0, not defining it is deprecated.', __METHOD__); diff --git a/src/Symfony/Component/Messenger/Handler/BatchHandlerInterface.php b/src/Symfony/Component/Messenger/Handler/BatchHandlerInterface.php index a2fce4e1bb1e..42a8590ee70a 100644 --- a/src/Symfony/Component/Messenger/Handler/BatchHandlerInterface.php +++ b/src/Symfony/Component/Messenger/Handler/BatchHandlerInterface.php @@ -23,7 +23,7 @@ interface BatchHandlerInterface * @return mixed The number of pending messages in the batch if $ack is not null, * the result from handling the message otherwise */ - // public function __invoke(object $message, Acknowledger $ack = null): mixed; + // public function __invoke(object $message, ?Acknowledger $ack = null): mixed; /** * Flushes any pending buffers. diff --git a/src/Symfony/Component/Messenger/Retry/RetryStrategyInterface.php b/src/Symfony/Component/Messenger/Retry/RetryStrategyInterface.php index 52c294bee2c6..7abce0df4147 100644 --- a/src/Symfony/Component/Messenger/Retry/RetryStrategyInterface.php +++ b/src/Symfony/Component/Messenger/Retry/RetryStrategyInterface.php @@ -23,12 +23,12 @@ interface RetryStrategyInterface /** * @param \Throwable|null $throwable The cause of the failed handling */ - public function isRetryable(Envelope $message/* , \Throwable $throwable = null */): bool; + public function isRetryable(Envelope $message/* , ?\Throwable $throwable = null */): bool; /** * @param \Throwable|null $throwable The cause of the failed handling * * @return int The time to delay/wait in milliseconds */ - public function getWaitingTime(Envelope $message/* , \Throwable $throwable = null */): int; + public function getWaitingTime(Envelope $message/* , ?\Throwable $throwable = null */): int; } diff --git a/src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md index 5dd9b64036de..de5e5458ed69 100644 --- a/src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md @@ -11,9 +11,9 @@ CHANGELOG * The bridge is not marked as `@experimental` anymore * [BC BREAK] Change signature of `EsendexTransport::__construct()` method from: - `public function __construct(string $token, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)` + `public function __construct(string $token, string $accountReference, string $from, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)` to: - `public function __construct(string $email, string $password, string $accountReference, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)` + `public function __construct(string $email, string $password, string $accountReference, string $from, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)` 5.2.0 ----- diff --git a/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md index 5759f578770f..9209c3c30650 100644 --- a/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md @@ -7,9 +7,9 @@ CHANGELOG * The bridge is not marked as `@experimental` anymore * [BC BREAK] Remove `GoogleChatTransport::setThreadKey()` method, this parameter should now be provided via the constructor, which has changed from: - `__construct(string $space, string $accessKey, string $accessToken, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)` + `__construct(string $space, string $accessKey, string $accessToken, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)` to: - `__construct(string $space, string $accessKey, string $accessToken, string $threadKey = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)` + `__construct(string $space, string $accessKey, string $accessToken, ?string $threadKey = null, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)` * [BC BREAK] Rename the parameter `threadKey` to `thread_key` in DSN 5.2.0 diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md index 8e154d13f0b8..39bc172f8cb7 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md @@ -6,9 +6,9 @@ CHANGELOG * The bridge is not marked as `@experimental` anymore * [BC BREAK] Change signature of `MattermostTransport::__construct()` method from: - `public function __construct(string $token, string $channel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, string $path = null)` + `public function __construct(string $token, string $channel, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null, ?string $path = null)` to: - `public function __construct(string $token, string $channel, ?string $path = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)` + `public function __construct(string $token, string $channel, ?string $path = null, ?HttpClientInterface $client = null, ?EventDispatcherInterface $dispatcher = null)` 5.1.0 ----- diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 29a91f904041..a4f2cc9f5e02 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -681,7 +681,7 @@ private function getMutatorMethod(string $class, string $property): ?array continue; } - // Parameter can be optional to allow things like: method(array $foo = null) + // Parameter can be optional to allow things like: method(?array $foo = null) if ($reflectionMethod->getNumberOfParameters() >= 1) { return [$reflectionMethod, $prefix]; } diff --git a/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolverInterface.php b/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolverInterface.php index ccacbe9df821..0e63d2fa0620 100644 --- a/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolverInterface.php +++ b/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolverInterface.php @@ -18,7 +18,7 @@ * * @author Johannes M. Schmitt * - * @method bool isAuthenticated(TokenInterface $token = null) + * @method bool isAuthenticated(?TokenInterface $token = null) */ interface AuthenticationTrustResolverInterface { diff --git a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php index cdb2bc2f9e63..cc59035bc253 100644 --- a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php @@ -68,7 +68,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface * * @throws \InvalidArgumentException */ - public function __construct(iterable $voters = [], /* AccessDecisionStrategyInterface */ $strategy = null) + public function __construct(iterable $voters = [], /* ?AccessDecisionStrategyInterface */ $strategy = null) { $this->voters = $voters; if (\is_string($strategy)) { diff --git a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php index 986f213ce9a6..5ee144b29563 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ChannelListener.php @@ -34,7 +34,7 @@ class ChannelListener extends AbstractListener private $httpPort; private $httpsPort; - public function __construct(AccessMapInterface $map, /* LoggerInterface */ $logger = null, /* int */ $httpPort = 80, /* int */ $httpsPort = 443) + public function __construct(AccessMapInterface $map, /* ?LoggerInterface */ $logger = null, /* int */ $httpPort = 80, /* int */ $httpsPort = 443) { if ($logger instanceof AuthenticationEntryPointInterface) { trigger_deprecation('symfony/security-http', '5.4', 'The "$authenticationEntryPoint" argument of "%s()" is deprecated.', __METHOD__); diff --git a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php index b373a6fa5fad..6f1b8f2f25a5 100644 --- a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php @@ -368,7 +368,7 @@ public static function getSignature(array $a) if (!$type instanceof \ReflectionNamedType) { $signature .= $type.' '; } else { - if (!$param->isOptional() && $param->allowsNull() && 'mixed' !== $type->getName()) { + if ($param->allowsNull() && 'mixed' !== $type->getName()) { $signature .= '?'; } $signature .= substr(strrchr('\\'.$type->getName(), '\\'), 1).' '; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php index cd6876cdff22..04d22816bb3e 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php @@ -141,7 +141,7 @@ public function testClassStub() $expectedDump = <<<'EODUMP' array:1 [ - 0 => "hello(?stdClass $a, stdClass $b = null)" + 0 => "hello(?stdClass $a, ?stdClass $b = null)" ] EODUMP; diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index dba799c55cfe..918f5f73d875 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -87,7 +87,7 @@ public function testGet() +foo: ""…3 +"bar": "bar" } - "closure" => Closure(\$a, PDO &\$b = null) {#%d + "closure" => Closure(\$a, ?PDO &\$b = null) {#%d class: "Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest" this: Symfony\Component\VarDumper\Tests\Dumper\CliDumperTest {#%d …} file: "%s%eTests%eFixtures%edumb-var.php" diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php index 8c9592e47b30..5f827c45fe76 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php @@ -83,7 +83,7 @@ public function testGet() +foo: "foo" +"bar": "bar" } - "closure" => Closure(\$a, PDO &\$b = null) {#%d + "closure" => Closure(\$a, ?PDO &\$b = null) {#%d class: "Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest" this: