diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index a2cb56164..0fee8a940 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -13,6 +13,7 @@ ->setRules([ 'psr_autoloading' => true, 'header_comment' => ['header' => $header], + 'nullable_type_declaration_for_default_null_value' => true, ]) ->setRiskyAllowed(true) ->setFinder( diff --git a/Context/Context.php b/Context/Context.php index 9945786fc..3f1a3e42f 100644 --- a/Context/Context.php +++ b/Context/Context.php @@ -111,7 +111,7 @@ public function getGroups(): ?array * * @param string[]|null $groups */ - public function setGroups(array $groups = null): self + public function setGroups(?array $groups = null): self { $this->groups = $groups; diff --git a/Controller/Annotations/Route.php b/Controller/Annotations/Route.php index 14884be1d..b3682e875 100644 --- a/Controller/Annotations/Route.php +++ b/Controller/Annotations/Route.php @@ -56,20 +56,20 @@ class Route extends CompatRoute public function __construct( $data = [], $path = null, - string $name = null, + ?string $name = null, array $requirements = [], array $options = [], array $defaults = [], - string $host = null, + ?string $host = null, $methods = [], $schemes = [], - string $condition = null, - int $priority = null, - string $locale = null, - string $format = null, - bool $utf8 = null, - bool $stateless = null, - string $env = null + ?string $condition = null, + ?int $priority = null, + ?string $locale = null, + ?string $format = null, + ?bool $utf8 = null, + ?bool $stateless = null, + ?string $env = null ) { // Use Reflection to get the constructor from the parent class two levels up (accounting for our compat definition) $method = (new \ReflectionClass($this))->getParentClass()->getParentClass()->getMethod('__construct'); diff --git a/DependencyInjection/FOSRestExtension.php b/DependencyInjection/FOSRestExtension.php index 4b6ff5cad..3f87d7b04 100644 --- a/DependencyInjection/FOSRestExtension.php +++ b/DependencyInjection/FOSRestExtension.php @@ -393,7 +393,7 @@ private function loadZoneMatcherListener(array $config, XmlFileLoader $loader, C } } - private function createZoneRequestMatcher(ContainerBuilder $container, ?string $path = null, ?string $host = null, array $methods = [], array $ips = null): Reference + private function createZoneRequestMatcher(ContainerBuilder $container, ?string $path = null, ?string $host = null, array $methods = [], ?array $ips = null): Reference { if ($methods) { $methods = array_map('strtoupper', (array) $methods); diff --git a/ErrorRenderer/SerializerErrorRenderer.php b/ErrorRenderer/SerializerErrorRenderer.php index 5e1971de8..37949e7b6 100644 --- a/ErrorRenderer/SerializerErrorRenderer.php +++ b/ErrorRenderer/SerializerErrorRenderer.php @@ -34,7 +34,7 @@ final class SerializerErrorRenderer implements ErrorRendererInterface * @param string|callable(FlattenException) $format * @param string|bool $debug */ - public function __construct(Serializer $serializer, $format, ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false) + public function __construct(Serializer $serializer, $format, ?ErrorRendererInterface $fallbackErrorRenderer = null, $debug = false) { if (!is_string($format) && !is_callable($format)) { 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))); diff --git a/EventListener/BodyListener.php b/EventListener/BodyListener.php index 1514b136d..001d16add 100644 --- a/EventListener/BodyListener.php +++ b/EventListener/BodyListener.php @@ -40,7 +40,7 @@ class BodyListener public function __construct( DecoderProviderInterface $decoderProvider, bool $throwExceptionOnUnsupportedContentType = false, - ArrayNormalizerInterface $arrayNormalizer = null, + ?ArrayNormalizerInterface $arrayNormalizer = null, bool $normalizeForms = false ) { $this->decoderProvider = $decoderProvider; diff --git a/Request/RequestBodyParamConverter.php b/Request/RequestBodyParamConverter.php index ae39855bc..877917711 100644 --- a/Request/RequestBodyParamConverter.php +++ b/Request/RequestBodyParamConverter.php @@ -41,7 +41,7 @@ public function __construct( Serializer $serializer, ?array $groups = null, ?string $version = null, - ValidatorInterface $validator = null, + ?ValidatorInterface $validator = null, ?string $validationErrorsArgument = null ) { $this->serializer = $serializer; diff --git a/Resources/doc/examples/RssHandler.php b/Resources/doc/examples/RssHandler.php index 9e93ef6cc..18dcbf5f4 100644 --- a/Resources/doc/examples/RssHandler.php +++ b/Resources/doc/examples/RssHandler.php @@ -48,7 +48,7 @@ class RssHandler { private $logger; - public function __construct(LoggerInterface $logger = null) + public function __construct(?LoggerInterface $logger = null) { $this->logger = $logger; } @@ -100,8 +100,8 @@ protected function createFeed($data, $format = 'rss') $entry->setLink($document['url']); $entry->addAuthor([ 'name' => $document['author'], - //'email' => '', - //'uri' => '', + // 'email' => '', + // 'uri' => '', ]); $entry->setDateModified($document['dateUpdated']->getTimestamp()); diff --git a/Serializer/JMSSerializerAdapter.php b/Serializer/JMSSerializerAdapter.php index e732840dc..20fcbf4b9 100644 --- a/Serializer/JMSSerializerAdapter.php +++ b/Serializer/JMSSerializerAdapter.php @@ -42,8 +42,8 @@ final class JMSSerializerAdapter implements Serializer public function __construct( SerializerInterface $serializer, - SerializationContextFactoryInterface $serializationContextFactory = null, - DeserializationContextFactoryInterface $deserializationContextFactory = null + ?SerializationContextFactoryInterface $serializationContextFactory = null, + ?DeserializationContextFactoryInterface $deserializationContextFactory = null ) { $this->serializer = $serializer; $this->serializationContextFactory = $serializationContextFactory; diff --git a/Serializer/Normalizer/FormErrorHandler.php b/Serializer/Normalizer/FormErrorHandler.php index 008847035..3a3da6f16 100644 --- a/Serializer/Normalizer/FormErrorHandler.php +++ b/Serializer/Normalizer/FormErrorHandler.php @@ -39,7 +39,7 @@ public static function getSubscribingMethods(): array return JMSFormErrorHandler::getSubscribingMethods(); } - public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type, Context $context = null) + public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null) { if ($context) { if ($context->hasAttribute('status_code')) { @@ -72,7 +72,7 @@ public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, return $this->formErrorHandler->serializeFormToXml($visitor, $form, $type); } - public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form, array $type, Context $context = null) + public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null) { $isRoot = !interface_exists(SerializationVisitorInterface::class) && null === $visitor->getRoot(); $result = $this->adaptFormArray($this->formErrorHandler->serializeFormToJson($visitor, $form, $type), $context); @@ -84,7 +84,7 @@ public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $for return $result; } - public function serializeFormToYml(YamlSerializationVisitor $visitor, Form $form, array $type, Context $context = null) + public function serializeFormToYml(YamlSerializationVisitor $visitor, Form $form, array $type, ?Context $context = null) { $isRoot = null === $visitor->getRoot(); $result = $this->adaptFormArray($this->formErrorHandler->serializeFormToYml($visitor, $form, $type), $context); @@ -101,7 +101,7 @@ public function __call($name, $arguments) return call_user_func_array([$this->formErrorHandler, $name], $arguments); } - private function adaptFormArray(\ArrayObject $serializedForm, Context $context = null) + private function adaptFormArray(\ArrayObject $serializedForm, ?Context $context = null) { $statusCode = $this->getStatusCode($context); if (null !== $statusCode) { @@ -115,7 +115,7 @@ private function adaptFormArray(\ArrayObject $serializedForm, Context $context = return $serializedForm; } - private function getStatusCode(Context $context = null) + private function getStatusCode(?Context $context = null) { if (null === $context) { return; diff --git a/Tests/Functional/Bundle/TestBundle/Security/ApiTokenGuardAuthenticator.php b/Tests/Functional/Bundle/TestBundle/Security/ApiTokenGuardAuthenticator.php index ff7637c27..23289a212 100644 --- a/Tests/Functional/Bundle/TestBundle/Security/ApiTokenGuardAuthenticator.php +++ b/Tests/Functional/Bundle/TestBundle/Security/ApiTokenGuardAuthenticator.php @@ -73,7 +73,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio /** * Called when authentication is needed, but it's not sent. */ - public function start(Request $request, AuthenticationException $authException = null): Response + public function start(Request $request, ?AuthenticationException $authException = null): Response { $data = ['message' => 'Authentication Required']; diff --git a/View/ViewHandler.php b/View/ViewHandler.php index 6e638fbb2..b6959e75f 100644 --- a/View/ViewHandler.php +++ b/View/ViewHandler.php @@ -58,7 +58,7 @@ private function __construct( UrlGeneratorInterface $urlGenerator, Serializer $serializer, RequestStack $requestStack, - array $formats = null, + ?array $formats = null, int $failedValidationCode = Response::HTTP_BAD_REQUEST, int $emptyContentCode = Response::HTTP_NO_CONTENT, bool $serializeNull = false, @@ -83,7 +83,7 @@ public static function create( UrlGeneratorInterface $urlGenerator, Serializer $serializer, RequestStack $requestStack, - array $formats = null, + ?array $formats = null, int $failedValidationCode = Response::HTTP_BAD_REQUEST, int $emptyContentCode = Response::HTTP_NO_CONTENT, bool $serializeNull = false, @@ -137,7 +137,7 @@ public function registerHandler(string $format, callable $callable): void * * @throws UnsupportedMediaTypeHttpException */ - public function handle(View $view, Request $request = null): Response + public function handle(View $view, ?Request $request = null): Response { if (null === $request) { $request = $this->requestStack->getCurrentRequest(); diff --git a/View/ViewHandlerInterface.php b/View/ViewHandlerInterface.php index 3f839d75f..85d10c9b5 100644 --- a/View/ViewHandlerInterface.php +++ b/View/ViewHandlerInterface.php @@ -41,7 +41,7 @@ public function registerHandler(string $format, callable $callable); * * @return Response */ - public function handle(View $view, Request $request = null); + public function handle(View $view, ?Request $request = null); /** * @return Response