From 4981d1370bfb0677739475de850c000d952eb674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Wed, 17 Apr 2024 12:18:21 +0200 Subject: [PATCH] [CS] Fix explicit nullable types --- create_framework/separation_of_concerns.rst | 2 +- create_framework/templating.rst | 2 +- reference/dic_tags.rst | 2 +- reference/forms/types/enum.rst | 2 +- serializer/custom_context_builders.rst | 4 ++-- validation/custom_constraint.rst | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/create_framework/separation_of_concerns.rst b/create_framework/separation_of_concerns.rst index e0937fbdf45..5238b3aac42 100644 --- a/create_framework/separation_of_concerns.rst +++ b/create_framework/separation_of_concerns.rst @@ -120,7 +120,7 @@ And move the ``is_leap_year()`` function to its own class too:: class LeapYear { - public function isLeapYear(int $year = null): bool + public function isLeapYear(?int $year = null): bool { if (null === $year) { $year = date('Y'); diff --git a/create_framework/templating.rst b/create_framework/templating.rst index 07d7e38417c..282e75cbc94 100644 --- a/create_framework/templating.rst +++ b/create_framework/templating.rst @@ -146,7 +146,7 @@ framework does not need to be modified in any way, create a new use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing; - function is_leap_year(int $year = null): bool + function is_leap_year(?int $year = null): bool { if (null === $year) { $year = (int)date('Y'); diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 354e9cb0b4b..cf908c4dd24 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -490,7 +490,7 @@ the :class:`Symfony\\Component\\HttpKernel\\CacheWarmer\\CacheWarmerInterface` i class MyCustomWarmer implements CacheWarmerInterface { - public function warmUp(string $cacheDir, string $buildDir = null): array + public function warmUp(string $cacheDir, ?string $buildDir = null): array { // ... do some sort of operations to "warm" your cache diff --git a/reference/forms/types/enum.rst b/reference/forms/types/enum.rst index 1a2afbe470c..7a49128f28c 100644 --- a/reference/forms/types/enum.rst +++ b/reference/forms/types/enum.rst @@ -66,7 +66,7 @@ implement ``TranslatableInterface`` to translate or display custom labels:: case Center = 'Center aligned'; case Right = 'Right aligned'; - public function trans(TranslatorInterface $translator, string $locale = null): string + public function trans(TranslatorInterface $translator, ?string $locale = null): string { // Translate enum from name (Left, Center or Right) return $translator->trans($this->name, locale: $locale); diff --git a/serializer/custom_context_builders.rst b/serializer/custom_context_builders.rst index b40e432286d..31fba6c90f5 100644 --- a/serializer/custom_context_builders.rst +++ b/serializer/custom_context_builders.rst @@ -33,7 +33,7 @@ value is ``0000-00-00``. To do that you'll first have to create your normalizer: { use DenormalizerAwareTrait; - public function denormalize($data, string $type, string $format = null, array $context = []): mixed + public function denormalize($data, string $type, ?string $format = null, array $context = []): mixed { if ('0000-00-00' === $data) { return null; @@ -44,7 +44,7 @@ value is ``0000-00-00``. To do that you'll first have to create your normalizer: return $this->denormalizer->denormalize($data, $type, $format, $context); } - public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool + public function supportsDenormalization($data, string $type, ?string $format = null, array $context = []): bool { return true === ($context['zero_datetime_to_null'] ?? false) && is_a($type, \DateTimeInterface::class, true); diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index 4dacb0c9504..9d3fb920d6d 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -59,7 +59,7 @@ You can use ``#[HasNamedArguments]`` to make some constraint options required:: #[HasNamedArguments] public function __construct( public string $mode, - array $groups = null, + ?array $groups = null, mixed $payload = null, ) { parent::__construct([], $groups, $payload);