Skip to content

[CS] Fix more nullable types #19787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/expression_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,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());
Expand Down
6 changes: 3 additions & 3 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exists in your project::
$this->sportsperson = $sportsperson;
}

public function setCreatedAt(\DateTime $createdAt = null): void
public function setCreatedAt(?\DateTime $createdAt = null): void
{
$this->createdAt = $createdAt;
}
Expand Down Expand Up @@ -798,7 +798,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 ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
$dateCallback = function ($innerObject, $outerObject, string $attributeName, ?string $format = null, array $context = []) {
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
};

Expand Down Expand Up @@ -1605,7 +1605,7 @@ having unique identifiers::
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

// all callback parameters are optional (you can omit the ones you don't use)
$maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
$maxDepthHandler = function ($innerObject, $outerObject, string $attributeName, ?string $format = null, array $context = []) {
return '/foos/'.$innerObject->id;
};

Expand Down
4 changes: 2 additions & 2 deletions controller/error_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
public function normalize($exception, ?string $format = null, array $context = [])
{
return [
'content' => 'This is my custom problem normalizer.',
Expand All @@ -227,7 +227,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
];
}

public function supportsNormalization($data, string $format = null)
public function supportsNormalization($data, ?string $format = null)
{
return $data instanceof FlattenException;
}
Expand Down
2 changes: 1 addition & 1 deletion form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ The type would now look like::
])
;

$formModifier = function (FormInterface $form, Sport $sport = null) {
$formModifier = function (FormInterface $form, ?Sport $sport = null) {
$positions = null === $sport ? [] : $sport->getAvailablePositions();

$form->add('position', EntityType::class, [
Expand Down
2 changes: 1 addition & 1 deletion frontend/custom_version_strategy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ version string::
* @param string $manifestPath
* @param string|null $format
*/
public function __construct(string $manifestPath, string $format = null)
public function __construct(string $manifestPath, ?string $format = null)
{
$this->manifestPath = $manifestPath;
$this->format = $format ?: '%s?%s';
Expand Down
4 changes: 2 additions & 2 deletions http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ If you want to extend the behavior of a base HTTP client, you can use
{
private $decoratedClient;

public function __construct(HttpClientInterface $decoratedClient = null)
public function __construct(?HttpClientInterface $decoratedClient = null)
{
$this->decoratedClient = $decoratedClient ?? HttpClient::create();
}
Expand All @@ -1667,7 +1667,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);
}
Expand Down
2 changes: 1 addition & 1 deletion messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ provided in order to ease the declaration of these special handlers::
{
use BatchHandlerTrait;

public function __invoke(MyMessage $message, Acknowledger $ack = null)
public function __invoke(MyMessage $message, ?Acknowledger $ack = null)
{
return $this->handle($message, $ack);
}
Expand Down
2 changes: 1 addition & 1 deletion messenger/custom-transport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Here is a simplified example of a database transport::
/**
* @param FakeDatabase $db is used for demo purposes. It is not a real class.
*/
public function __construct(FakeDatabase $db, SerializerInterface $serializer = null)
public function __construct(FakeDatabase $db, ?SerializerInterface $serializer = null)
{
$this->db = $db;
$this->serializer = $serializer ?? new PhpSerializer();
Expand Down
2 changes: 1 addition & 1 deletion notifier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ and its ``asChatMessage()`` method::
$this->price = $price;
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion profiler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ request::

class RequestCollector extends AbstractDataCollector
{
public function collect(Request $request, Response $response, \Throwable $exception = null)
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
{
$this->data = [
'method' => $request->getMethod(),
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/File.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type. The ``Author`` class might look as follows::
{
protected $bioFile;

public function setBioFile(File $file = null)
public function setBioFile(?File $file = null)
{
$this->bioFile = $file;
}
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/Image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ would be a ``file`` type. The ``Author`` class might look as follows::
{
protected $headshot;

public function setHeadshot(File $file = null)
public function setHeadshot(?File $file = null)
{
$this->headshot = $file;
}
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ the value is removed from the collection. For example::

$builder->add('users', CollectionType::class, [
// ...
'delete_empty' => function (User $user = null) {
'delete_empty' => function (?User $user = null) {
return null === $user || empty($user->getFirstName());
},
]);
Expand Down
8 changes: 4 additions & 4 deletions routing/custom_route_loader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ you do. The resource name itself is not actually used in the example::
{
private $isLoaded = false;

public function load($resource, string $type = null)
public function load($resource, ?string $type = null)
{
if (true === $this->isLoaded) {
throw new \RuntimeException('Do not add the "extra" loader twice');
Expand All @@ -267,7 +267,7 @@ you do. The resource name itself is not actually used in the example::
return $routes;
}

public function supports($resource, string $type = null)
public function supports($resource, ?string $type = null)
{
return 'extra' === $type;
}
Expand Down Expand Up @@ -412,7 +412,7 @@ configuration file - you can call the

class AdvancedLoader extends Loader
{
public function load($resource, string $type = null)
public function load($resource, ?string $type = null)
{
$routes = new RouteCollection();

Expand All @@ -426,7 +426,7 @@ configuration file - you can call the
return $routes;
}

public function supports($resource, string $type = null)
public function supports($resource, ?string $type = null)
{
return 'advanced_extra' === $type;
}
Expand Down
2 changes: 1 addition & 1 deletion security/access_denied_handler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ unauthenticated user tries to access a protected resource::
$this->urlGenerator = $urlGenerator;
}

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.');
Expand Down
2 changes: 1 addition & 1 deletion security/login_link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,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);

Expand Down
4 changes: 2 additions & 2 deletions serializer/custom_normalizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
$this->normalizer = $normalizer;
}

public function normalize($topic, string $format = null, array $context = [])
public function normalize($topic, ?string $format = null, array $context = [])
{
$data = $this->normalizer->normalize($topic, $format, $context);

Expand All @@ -45,7 +45,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
return $data;
}

public function supportsNormalization($data, string $format = null, array $context = [])
public function supportsNormalization($data, ?string $format = null, array $context = [])
{
return $data instanceof Topic;
}
Expand Down
8 changes: 4 additions & 4 deletions validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
public $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);
Expand Down Expand Up @@ -270,9 +270,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 = []
) {
Expand Down