diff --git a/components/expression_language.rst b/components/expression_language.rst index 8092ce491ed..1563ebf1aeb 100644 --- a/components/expression_language.rst +++ b/components/expression_language.rst @@ -385,7 +385,7 @@ or by using the second argument of the constructor:: class ExpressionLanguage extends BaseExpressionLanguage { - public function __construct(CacheItemPoolInterface $cache = null, array $providers = []) + public function __construct(?CacheItemPoolInterface $cache = null, array $providers = []) { // prepends the default provider to let users override it array_unshift($providers, new StringExpressionLanguageProvider()); diff --git a/components/serializer.rst b/components/serializer.rst index 0cd71ec1cc7..62f8af323b1 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -118,7 +118,7 @@ exists in your project:: $this->sportsperson = $sportsperson; } - public function setCreatedAt(\DateTimeInterface $createdAt = null): void + public function setCreatedAt(?\DateTimeInterface $createdAt = null): void { $this->createdAt = $createdAt; } @@ -751,7 +751,7 @@ When serializing, you can set a callback to format a specific object property:: $encoder = new JsonEncoder(); // all callback parameters are optional (you can omit the ones you don't use) - $dateCallback = function (object $innerObject, object $outerObject, string $attributeName, string $format = null, array $context = []): string { + $dateCallback = function (object $innerObject, object $outerObject, string $attributeName, ?string $format = null, array $context = []): string { return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : ''; }; @@ -1629,7 +1629,7 @@ having unique identifiers:: $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); // all callback parameters are optional (you can omit the ones you don't use) - $maxDepthHandler = function (object $innerObject, object $outerObject, string $attributeName, string $format = null, array $context = []): string { + $maxDepthHandler = function (object $innerObject, object $outerObject, string $attributeName, ?string $format = null, array $context = []): string { return '/foos/'.$innerObject->id; }; diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 52dff49731f..001e637c03e 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -216,7 +216,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input:: class MyCustomProblemNormalizer implements NormalizerInterface { - public function normalize($exception, string $format = null, array $context = []): array + public function normalize($exception, ?string $format = null, array $context = []): array { return [ 'content' => 'This is my custom problem normalizer.', @@ -227,7 +227,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input:: ]; } - public function supportsNormalization($data, string $format = null, array $context = []): bool + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return $data instanceof FlattenException; } diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index 72acc7eee0d..09be80ebb5a 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -455,7 +455,7 @@ The type would now look like:: ]) ; - $formModifier = function (FormInterface $form, Sport $sport = null): void { + $formModifier = function (FormInterface $form, ?Sport $sport = null): void { $positions = null === $sport ? [] : $sport->getAvailablePositions(); $form->add('position', EntityType::class, [ @@ -487,7 +487,7 @@ The type would now look like:: $formModifier($event->getForm()->getParent(), $sport); } ); - + // by default, action does not appear in the
tag // you can set this value by passing the controller route $builder->setAction($options['action']); diff --git a/http_client.rst b/http_client.rst index 429be01c32e..361809f5614 100644 --- a/http_client.rst +++ b/http_client.rst @@ -1804,7 +1804,7 @@ If you want to extend the behavior of a base HTTP client, you can use class MyExtendedHttpClient implements HttpClientInterface { public function __construct( - private HttpClientInterface $decoratedClient = null + private ?HttpClientInterface $decoratedClient = null ) { $this->decoratedClient ??= HttpClient::create(); } @@ -1820,7 +1820,7 @@ If you want to extend the behavior of a base HTTP client, you can use return $response; } - public function stream($responses, float $timeout = null): ResponseStreamInterface + public function stream($responses, ?float $timeout = null): ResponseStreamInterface { return $this->decoratedClient->stream($responses, $timeout); } diff --git a/messenger.rst b/messenger.rst index 6a67dfd2778..05d1c9262c7 100644 --- a/messenger.rst +++ b/messenger.rst @@ -2621,7 +2621,7 @@ provided in order to ease the declaration of these special handlers:: { use BatchHandlerTrait; - public function __invoke(MyMessage $message, Acknowledger $ack = null): mixed + public function __invoke(MyMessage $message, ?Acknowledger $ack = null): mixed { return $this->handle($message, $ack); } diff --git a/messenger/custom-transport.rst b/messenger/custom-transport.rst index d9cc9fa1abf..7d1698126d1 100644 --- a/messenger/custom-transport.rst +++ b/messenger/custom-transport.rst @@ -51,7 +51,7 @@ Here is a simplified example of a database transport:: */ public function __construct( private FakeDatabase $db, - SerializerInterface $serializer = null, + ?SerializerInterface $serializer = null, ) { $this->serializer = $serializer ?? new PhpSerializer(); } diff --git a/notifier.rst b/notifier.rst index 6ed993b8c2c..9b9eaf957bd 100644 --- a/notifier.rst +++ b/notifier.rst @@ -824,7 +824,7 @@ and its ``asChatMessage()`` method:: ) { } - public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage + public function asChatMessage(RecipientInterface $recipient, ?string $transport = null): ?ChatMessage { // Add a custom subject and emoji if the message is sent to Slack if ('slack' === $transport) { diff --git a/profiler.rst b/profiler.rst index 81c3bbfafed..c1dc9a5112f 100644 --- a/profiler.rst +++ b/profiler.rst @@ -289,7 +289,7 @@ request:: class RequestCollector extends AbstractDataCollector { - public function collect(Request $request, Response $response, \Throwable $exception = null): void + public function collect(Request $request, Response $response, ?\Throwable $exception = null): void { $this->data = [ 'method' => $request->getMethod(), diff --git a/reference/constraints/File.rst b/reference/constraints/File.rst index 1c12ce0f103..0840a36aede 100644 --- a/reference/constraints/File.rst +++ b/reference/constraints/File.rst @@ -40,7 +40,7 @@ type. The ``Author`` class might look as follows:: { protected File $bioFile; - public function setBioFile(File $file = null): void + public function setBioFile(?File $file = null): void { $this->bioFile = $file; } diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst index 22a7bc1a688..48dc1d5e0ed 100644 --- a/reference/constraints/Image.rst +++ b/reference/constraints/Image.rst @@ -35,7 +35,7 @@ would be a ``file`` type. The ``Author`` class might look as follows:: { protected File $headshot; - public function setHeadshot(File $file = null): void + public function setHeadshot(?File $file = null): void { $this->headshot = $file; } diff --git a/reference/forms/types/collection.rst b/reference/forms/types/collection.rst index 2950c6d0304..d584e4152b4 100644 --- a/reference/forms/types/collection.rst +++ b/reference/forms/types/collection.rst @@ -160,7 +160,7 @@ the value is removed from the collection. For example:: $builder->add('users', CollectionType::class, [ // ... - 'delete_empty' => function (User $user = null): bool { + 'delete_empty' => function (?User $user = null): bool { return null === $user || empty($user->getFirstName()); }, ]); diff --git a/routing/custom_route_loader.rst b/routing/custom_route_loader.rst index d02e6b31519..7c76bb41e5f 100644 --- a/routing/custom_route_loader.rst +++ b/routing/custom_route_loader.rst @@ -280,7 +280,7 @@ you do. The resource name itself is not actually used in the example:: { private bool $isLoaded = false; - public function load($resource, string $type = null): RouteCollection + public function load($resource, ?string $type = null): RouteCollection { if (true === $this->isLoaded) { throw new \RuntimeException('Do not add the "extra" loader twice'); @@ -307,7 +307,7 @@ you do. The resource name itself is not actually used in the example:: return $routes; } - public function supports($resource, string $type = null): bool + public function supports($resource, ?string $type = null): bool { return 'extra' === $type; } @@ -452,7 +452,7 @@ configuration file - you can call the class AdvancedLoader extends Loader { - public function load($resource, string $type = null): RouteCollection + public function load($resource, ?string $type = null): RouteCollection { $routes = new RouteCollection(); @@ -466,7 +466,7 @@ configuration file - you can call the return $routes; } - public function supports($resource, string $type = null): bool + public function supports($resource, ?string $type = null): bool { return 'advanced_extra' === $type; } diff --git a/security/access_denied_handler.rst b/security/access_denied_handler.rst index 5671b0538a1..37490e3120b 100644 --- a/security/access_denied_handler.rst +++ b/security/access_denied_handler.rst @@ -38,7 +38,7 @@ unauthenticated user tries to access a protected resource:: ) { } - public function start(Request $request, AuthenticationException $authException = null): RedirectResponse + public function start(Request $request, ?AuthenticationException $authException = null): RedirectResponse { // add a custom flash message and redirect to the login page $request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.'); diff --git a/security/login_link.rst b/security/login_link.rst index faa1d353514..0f642e1ad15 100644 --- a/security/login_link.rst +++ b/security/login_link.rst @@ -283,7 +283,7 @@ This will send an email like this to the user: class CustomLoginLinkNotification extends LoginLinkNotification { - public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage + public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage { $emailMessage = parent::asEmailMessage($recipient, $transport); diff --git a/serializer/custom_normalizer.rst b/serializer/custom_normalizer.rst index 124e2f38b8a..3d2e7cd2a7e 100644 --- a/serializer/custom_normalizer.rst +++ b/serializer/custom_normalizer.rst @@ -32,7 +32,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``: ) { } - public function normalize($topic, string $format = null, array $context = []): array + public function normalize($topic, ?string $format = null, array $context = []): array { $data = $this->normalizer->normalize($topic, $format, $context); @@ -44,7 +44,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``: return $data; } - public function supportsNormalization($data, string $format = null, array $context = []): bool + public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return $data instanceof Topic; } diff --git a/testing.rst b/testing.rst index 079f05eced3..989271983dc 100644 --- a/testing.rst +++ b/testing.rst @@ -560,13 +560,13 @@ returns a ``Crawler`` instance. The full signature of the ``request()`` method is:: - request( + public function request( string $method, string $uri, array $parameters = [], array $files = [], array $server = [], - string $content = null, + ?string $content = null, bool $changeHistory = true ): Crawler @@ -971,7 +971,7 @@ Response Assertions Asserts that the response was successful (HTTP status is 2xx). ``assertResponseStatusCodeSame(int $expectedCode, string $message = '')`` Asserts a specific HTTP status code. -``assertResponseRedirects(string $expectedLocation = null, int $expectedCode = null, string $message = '')`` +``assertResponseRedirects(?string $expectedLocation = null, ?int $expectedCode = null, string $message = '')`` Asserts the response is a redirect response (optionally, you can check the target location and status code). The excepted location can be either an absolute or a relative path. @@ -980,10 +980,10 @@ Response Assertions ``assertResponseHeaderSame(string $headerName, string $expectedValue, string $message = '')``/``assertResponseHeaderNotSame(string $headerName, string $expectedValue, string $message = '')`` Asserts the given header does (not) contain the expected value on the response, e.g. ``assertResponseHeaderSame('content-type', 'application/octet-stream');``. -``assertResponseHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``/``assertResponseNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')`` +``assertResponseHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``/``assertResponseNotHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')`` Asserts the given cookie is present in the response (optionally checking for a specific cookie path or domain). -``assertResponseCookieValueSame(string $name, string $expectedValue, string $path = '/', string $domain = null, string $message = '')`` +``assertResponseCookieValueSame(string $name, string $expectedValue, string $path = '/', ?string $domain = null, string $message = '')`` Asserts the given cookie is present and set to the expected value. ``assertResponseFormatSame(?string $expectedFormat, string $message = '')`` Asserts the response format returned by the @@ -1009,10 +1009,10 @@ Request Assertions Browser Assertions .................. -``assertBrowserHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')``/``assertBrowserNotHasCookie(string $name, string $path = '/', string $domain = null, string $message = '')`` +``assertBrowserHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')``/``assertBrowserNotHasCookie(string $name, string $path = '/', ?string $domain = null, string $message = '')`` Asserts that the test Client does (not) have the given cookie set (meaning, the cookie was set by any response in the test). -``assertBrowserCookieValueSame(string $name, string $expectedValue, string $path = '/', string $domain = null, string $message = '')`` +``assertBrowserCookieValueSame(string $name, string $expectedValue, string $path = '/', ?string $domain = null, string $message = '')`` Asserts the given cookie in the test Client is set to the expected value. ``assertThatForClient(Constraint $constraint, string $message = '')`` @@ -1072,18 +1072,18 @@ Crawler Assertions Mailer Assertions ................. -``assertEmailCount(int $count, string $transport = null, string $message = '')`` +``assertEmailCount(int $count, ?string $transport = null, string $message = '')`` Asserts that the expected number of emails was sent. -``assertQueuedEmailCount(int $count, string $transport = null, string $message = '')`` +``assertQueuedEmailCount(int $count, ?string $transport = null, string $message = '')`` Asserts that the expected number of emails was queued (e.g. using the Messenger component). ``assertEmailIsQueued(MessageEvent $event, string $message = '')``/``assertEmailIsNotQueued(MessageEvent $event, string $message = '')`` Asserts that the given mailer event is (not) queued. Use - ``getMailerEvent(int $index = 0, string $transport = null)`` to + ``getMailerEvent(int $index = 0, ?string $transport = null)`` to retrieve a mailer event by index. ``assertEmailAttachmentCount(RawMessage $email, int $count, string $message = '')`` Asserts that the given email has the expected number of attachments. Use - ``getMailerMessage(int $index = 0, string $transport = null)`` to + ``getMailerMessage(int $index = 0, ?string $transport = null)`` to retrieve a specific email by index. ``assertEmailTextBodyContains(RawMessage $email, string $text, string $message = '')``/``assertEmailTextBodyNotContains(RawMessage $email, string $text, string $message = '')`` Asserts that the text body of the given email does (not) contain the diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index b489c3ef68a..0f7016d9653 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -27,7 +27,7 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen public string $mode = 'strict'; // all configurable options must be passed to the constructor - public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null) + public function __construct(?string $mode = null, ?string $message = null, ?array $groups = null, $payload = null) { parent::__construct([], $groups, $payload); @@ -247,9 +247,9 @@ define those options as public properties on the constraint class:: public function __construct( $mandatoryFooOption, - string $message = null, - bool $optionalBarOption = null, - array $groups = null, + ?string $message = null, + ?bool $optionalBarOption = null, + ?array $groups = null, $payload = null, array $options = [] ) {