Skip to content

Commit e709d9a

Browse files
authored
Merge pull request #2412 from W0rma/nullable-parameter-types
Declare nullable parameter types explicitly
2 parents d2a0cb9 + 96de6ac commit e709d9a

File tree

13 files changed

+30
-29
lines changed

13 files changed

+30
-29
lines changed

.php-cs-fixer.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
->setRules([
1414
'psr_autoloading' => true,
1515
'header_comment' => ['header' => $header],
16+
'nullable_type_declaration_for_default_null_value' => true,
1617
])
1718
->setRiskyAllowed(true)
1819
->setFinder(

Context/Context.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getGroups(): ?array
111111
*
112112
* @param string[]|null $groups
113113
*/
114-
public function setGroups(array $groups = null): self
114+
public function setGroups(?array $groups = null): self
115115
{
116116
$this->groups = $groups;
117117

Controller/Annotations/Route.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ class Route extends CompatRoute
5656
public function __construct(
5757
$data = [],
5858
$path = null,
59-
string $name = null,
59+
?string $name = null,
6060
array $requirements = [],
6161
array $options = [],
6262
array $defaults = [],
63-
string $host = null,
63+
?string $host = null,
6464
$methods = [],
6565
$schemes = [],
66-
string $condition = null,
67-
int $priority = null,
68-
string $locale = null,
69-
string $format = null,
70-
bool $utf8 = null,
71-
bool $stateless = null,
72-
string $env = null
66+
?string $condition = null,
67+
?int $priority = null,
68+
?string $locale = null,
69+
?string $format = null,
70+
?bool $utf8 = null,
71+
?bool $stateless = null,
72+
?string $env = null
7373
) {
7474
// Use Reflection to get the constructor from the parent class two levels up (accounting for our compat definition)
7575
$method = (new \ReflectionClass($this))->getParentClass()->getParentClass()->getMethod('__construct');

DependencyInjection/FOSRestExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, C
393393
}
394394
}
395395

396-
private function createZoneRequestMatcher(ContainerBuilder $container, ?string $path = null, ?string $host = null, array $methods = [], array $ips = null): Reference
396+
private function createZoneRequestMatcher(ContainerBuilder $container, ?string $path = null, ?string $host = null, array $methods = [], ?array $ips = null): Reference
397397
{
398398
if ($methods) {
399399
$methods = array_map('strtoupper', (array) $methods);

ErrorRenderer/SerializerErrorRenderer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class SerializerErrorRenderer implements ErrorRendererInterface
3434
* @param string|callable(FlattenException) $format
3535
* @param string|bool $debug
3636
*/
37-
public function __construct(Serializer $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
37+
public function __construct(Serializer $serializer, $format, ?ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false)
3838
{
3939
if (!is_string($format) && !is_callable($format)) {
4040
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a string or a callable, "%s" given.', __METHOD__, \is_object($format) ? \get_class($format) : \gettype($format)));

EventListener/BodyListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BodyListener
4040
public function __construct(
4141
DecoderProviderInterface $decoderProvider,
4242
bool $throwExceptionOnUnsupportedContentType = false,
43-
ArrayNormalizerInterface $arrayNormalizer = null,
43+
?ArrayNormalizerInterface $arrayNormalizer = null,
4444
bool $normalizeForms = false
4545
) {
4646
$this->decoderProvider = $decoderProvider;

Request/RequestBodyParamConverter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
Serializer $serializer,
4242
?array $groups = null,
4343
?string $version = null,
44-
ValidatorInterface $validator = null,
44+
?ValidatorInterface $validator = null,
4545
?string $validationErrorsArgument = null
4646
) {
4747
$this->serializer = $serializer;

Resources/doc/examples/RssHandler.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class RssHandler
4848
{
4949
private $logger;
5050

51-
public function __construct(LoggerInterface $logger = null)
51+
public function __construct(?LoggerInterface $logger = null)
5252
{
5353
$this->logger = $logger;
5454
}
@@ -100,8 +100,8 @@ protected function createFeed($data, $format = 'rss')
100100
$entry->setLink($document['url']);
101101
$entry->addAuthor([
102102
'name' => $document['author'],
103-
//'email' => '',
104-
//'uri' => '',
103+
// 'email' => '',
104+
// 'uri' => '',
105105
]);
106106

107107
$entry->setDateModified($document['dateUpdated']->getTimestamp());

Serializer/JMSSerializerAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ final class JMSSerializerAdapter implements Serializer
4242

4343
public function __construct(
4444
SerializerInterface $serializer,
45-
SerializationContextFactoryInterface $serializationContextFactory = null,
46-
DeserializationContextFactoryInterface $deserializationContextFactory = null
45+
?SerializationContextFactoryInterface $serializationContextFactory = null,
46+
?DeserializationContextFactoryInterface $deserializationContextFactory = null
4747
) {
4848
$this->serializer = $serializer;
4949
$this->serializationContextFactory = $serializationContextFactory;

Serializer/Normalizer/FormErrorHandler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function getSubscribingMethods(): array
3939
return JMSFormErrorHandler::getSubscribingMethods();
4040
}
4141

42-
public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type, Context $context = null)
42+
public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null)
4343
{
4444
if ($context) {
4545
if ($context->hasAttribute('status_code')) {
@@ -72,7 +72,7 @@ public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form,
7272
return $this->formErrorHandler->serializeFormToXml($visitor, $form, $type);
7373
}
7474

75-
public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form, array $type, Context $context = null)
75+
public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null)
7676
{
7777
$isRoot = !interface_exists(SerializationVisitorInterface::class) && null === $visitor->getRoot();
7878
$result = $this->adaptFormArray($this->formErrorHandler->serializeFormToJson($visitor, $form, $type), $context);
@@ -84,7 +84,7 @@ public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $for
8484
return $result;
8585
}
8686

87-
public function serializeFormToYml(YamlSerializationVisitor $visitor, Form $form, array $type, Context $context = null)
87+
public function serializeFormToYml(YamlSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null)
8888
{
8989
$isRoot = null === $visitor->getRoot();
9090
$result = $this->adaptFormArray($this->formErrorHandler->serializeFormToYml($visitor, $form, $type), $context);
@@ -101,7 +101,7 @@ public function __call($name, $arguments)
101101
return call_user_func_array([$this->formErrorHandler, $name], $arguments);
102102
}
103103

104-
private function adaptFormArray(\ArrayObject $serializedForm, Context $context = null)
104+
private function adaptFormArray(\ArrayObject $serializedForm, ?Context $context = null)
105105
{
106106
$statusCode = $this->getStatusCode($context);
107107
if (null !== $statusCode) {
@@ -115,7 +115,7 @@ private function adaptFormArray(\ArrayObject $serializedForm, Context $context =
115115
return $serializedForm;
116116
}
117117

118-
private function getStatusCode(Context $context = null)
118+
private function getStatusCode(?Context $context = null)
119119
{
120120
if (null === $context) {
121121
return;

Tests/Functional/Bundle/TestBundle/Security/ApiTokenGuardAuthenticator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7373
/**
7474
* Called when authentication is needed, but it's not sent.
7575
*/
76-
public function start(Request $request, AuthenticationException $authException = null): Response
76+
public function start(Request $request, ?AuthenticationException $authException = null): Response
7777
{
7878
$data = ['message' => 'Authentication Required'];
7979

View/ViewHandler.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private function __construct(
5858
UrlGeneratorInterface $urlGenerator,
5959
Serializer $serializer,
6060
RequestStack $requestStack,
61-
array $formats = null,
61+
?array $formats = null,
6262
int $failedValidationCode = Response::HTTP_BAD_REQUEST,
6363
int $emptyContentCode = Response::HTTP_NO_CONTENT,
6464
bool $serializeNull = false,
@@ -83,7 +83,7 @@ public static function create(
8383
UrlGeneratorInterface $urlGenerator,
8484
Serializer $serializer,
8585
RequestStack $requestStack,
86-
array $formats = null,
86+
?array $formats = null,
8787
int $failedValidationCode = Response::HTTP_BAD_REQUEST,
8888
int $emptyContentCode = Response::HTTP_NO_CONTENT,
8989
bool $serializeNull = false,
@@ -137,7 +137,7 @@ public function registerHandler(string $format, callable $callable): void
137137
*
138138
* @throws UnsupportedMediaTypeHttpException
139139
*/
140-
public function handle(View $view, Request $request = null): Response
140+
public function handle(View $view, ?Request $request = null): Response
141141
{
142142
if (null === $request) {
143143
$request = $this->requestStack->getCurrentRequest();

View/ViewHandlerInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function registerHandler(string $format, callable $callable);
4141
*
4242
* @return Response
4343
*/
44-
public function handle(View $view, Request $request = null);
44+
public function handle(View $view, ?Request $request = null);
4545

4646
/**
4747
* @return Response

0 commit comments

Comments
 (0)