Skip to content

Commit

Permalink
Declare nullable parameter types explicitly
Browse files Browse the repository at this point in the history
Fixes a deprecation warning in PHP 8.4
  • Loading branch information
Dieter Beck committed Aug 1, 2024
1 parent d2a0cb9 commit ed2412d
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
->setRules([
'psr_autoloading' => true,
'header_comment' => ['header' => $header],
'nullable_type_declaration_for_default_null_value' => true,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
2 changes: 1 addition & 1 deletion Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 9 additions & 9 deletions Controller/Annotations/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/FOSRestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ErrorRenderer/SerializerErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion EventListener/BodyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Request/RequestBodyParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/examples/RssHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RssHandler
{
private $logger;

public function __construct(LoggerInterface $logger = null)
public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger;
}
Expand Down
4 changes: 2 additions & 2 deletions Serializer/JMSSerializerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Serializer/Normalizer/FormErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
6 changes: 3 additions & 3 deletions View/ViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion View/ViewHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed2412d

Please sign in to comment.