Skip to content

Commit

Permalink
minor #54335 Make more nullable types explicit (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

Make more nullable types explicit

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

This time in comments and in dumps.

Commits
-------

73d769e Make more nullable types explicit
  • Loading branch information
nicolas-grekas committed Mar 19, 2024
2 parents b9b35dc + 73d769e commit 998fa9d
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Mailer/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -183,7 +183,7 @@ public function fromDsnObject(Dsn $dsn): TransportInterface
*
* @return \Traversable<int, TransportFactoryInterface>
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Bridge/Mattermost/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @method bool isAuthenticated(TokenInterface $token = null)
* @method bool isAuthenticated(?TokenInterface $token = null)
*/
interface AuthenticationTrustResolverInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).' ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testClassStub()

$expectedDump = <<<'EODUMP'
<foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp data-depth=1 class=sf-dump-expanded>
<span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:10" rel="noopener noreferrer"><span class=sf-dump-str title="39 characters">hello(?stdClass $a, stdClass $b = null)</span></a>"
<span class=sf-dump-index>0</span> => "<a href="%sFooInterface.php:10" rel="noopener noreferrer"><span class=sf-dump-str title="40 characters">hello(?stdClass $a, ?stdClass $b = null)</span></a>"
</samp>]
</bar>
EODUMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testGet()
+<span class=sf-dump-public title="Public property">foo</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
+"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"
</samp>}
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure(\$a, PDO &amp;\$b = null)</span> {<a class=sf-dump-ref>#%d</a><samp data-depth=2 class=sf-dump-compact>
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure(\$a, ?PDO &amp;\$b = null)</span> {<a class=sf-dump-ref>#%d</a><samp data-depth=2 class=sf-dump-compact>
<span class=sf-dump-meta>class</span>: "<span class=sf-dump-str title="Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest
55 characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-class">Symfony\Component\VarDumper\Tests\Dumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-class">\</span>HtmlDumperTest</span>"
<span class=sf-dump-meta>this</span>: <span class=sf-dump-note title="Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\VarDumper;

VarDumper::setHandler(function ($var, string $label = null) {
VarDumper::setHandler(function ($var, ?string $label = null) {
$dumper = new DumpDataCollector();
$cloner = new VarCloner();
$handler = function ($var, string $label = null) use ($dumper, $cloner) {
$handler = function ($var, ?string $label = null) use ($dumper, $cloner) {
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
Expand Down

0 comments on commit 998fa9d

Please sign in to comment.