8000 [CS] Fix more nullable types · symfony/symfony-docs@d896411 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d896411

Browse files
committed
[CS] Fix more nullable types
Follows #19786
1 parent d6d2363 commit d896411

18 files changed

+29
-29
lines changed

components/expression_language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ or by using the second argument of the constructor::
359359

360360
class ExpressionLanguage extends BaseExpressionLanguage
361361
{
362-
public function __construct(CacheItemPoolInterface $cache = null, array $providers = [])
362+
public function __construct(?CacheItemPoolInterface $cache = null, array $providers = [])
363363
{
364364
// prepends the default provider to let users override it
365365
array_unshift($providers, new StringExpressionLanguageProvider());

components/serializer.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ exists in your project::
118118
$this->sportsperson = $sportsperson;
119119
}
120120

121-
public function setCreatedAt(\DateTime $createdAt = null): void
121+
public function setCreatedAt(?\DateTime $createdAt = null): void
122122
{
123123
$this->createdAt = $createdAt;
124124
}
@@ -798,7 +798,7 @@ When serializing, you can set a callback to format a specific object property::
798798
$encoder = new JsonEncoder();
799799

800800
// all callback parameters are optional (you can omit the ones you don't use)
801-
$dateCallback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
801+
$dateCallback = function ($innerObject, $outerObject, string $attributeName, ?string $format = null, array $context = []) {
802802
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
803803
};
804804

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

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

controller/error_pages.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
216216

217217
class MyCustomProblemNormalizer implements NormalizerInterface
218218
{
219-
public function normalize($exception, string $format = null, array $context = [])
219+
public function normalize($exception, ?string $format = null, array $context = [])
220220
{
221221
return [
222222
'content' => 'This is my custom problem normalizer.',
@@ -227,7 +227,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
227227
];
228228
}
229229

230-
public function supportsNormalization($data, string $format = null)
230+
public function supportsNormalization($data, ?string $format = null)
231231
{
232232
return $data instanceof FlattenException;
233233
}

form/dynamic_form_modification.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ The type would now look like::
459459
])
460460
;
461461

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

465465
$form->add('position', EntityType::class, [

frontend/custom_version_strategy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ version string::
6868
* @param string $manifestPath
6969
* @param string|null $format
7070
*/
71-
public function __construct(string $manifestPath, string $format = null)
71+
public function __construct(string $manifestPath, ?string $format = null)
7272
{
7373
$this->manifestPath = $manifestPath;
7474
$this->format = $format ?: '%s?%s';

http_client.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ If you want to extend the behavior of a base HTTP client, you can use
16511651
{
16521652
private $decoratedClient;
16531653

1654-
public function __construct(HttpClientInterface $decoratedClient = null)
1654+
public function __construct(?HttpClientInterface $decoratedClient = null)
16551655
{
16561656
$this->decoratedClient = $decoratedClient ?? HttpClient::create();
16571657
}
@@ -1667,7 +1667,7 @@ If you want to extend the behavior of a base HTTP client, you can use
16671667
return $response;
16681668
}
16691669

1670-
public function stream($responses, float $timeout = null): ResponseStreamInterface
1670+
public function stream($responses, ?float $timeout = null): ResponseStreamInterface
16711671
{
16721672
return $this->decoratedClient->stream($responses, $timeout);
16731673
}

messenger.rst

Lines changed: 1 addition & 1 deletion
10000
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ provided in order to ease the declaration of these special handlers::
22202220
{
22212221
use BatchHandlerTrait;
22222222

2223-
public function __invoke(MyMessage $message, Acknowledger $ack = null)
2223+
public function __invoke(MyMessage $message, ?Acknowledger $ack = null)
22242224
{
22252225
return $this->handle($message, $ack);
22262226
}

messenger/custom-transport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Here is a simplified example of a database transport::
5050
/**
5151
* @param FakeDatabase $db is used for demo purposes. It is not a real class.
5252
*/
53-
public function __construct(FakeDatabase $db, SerializerInterface $serializer = null)
53+
public function __construct(FakeDatabase $db, ?SerializerInterface $serializer = null)
5454
{
5555
$this->db = $db;
5656
$this->serializer = $serializer ?? new PhpSerializer();

notifier.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ and its ``asChatMessage()`` method::
778778
$this->price = $price;
779779
}
780780

781-
public function asChatMessage(RecipientInterface $recipient, string $transport = null): ?ChatMessage
781+
public function asChatMessage(RecipientInterface $recipient, ?string $transport = null): ?ChatMessage
782782
{
783783
// Add a custom subject and emoji if the message is sent to Slack
784784
if ('slack' === $transport) {

profiler.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ request::
255255

256256
class RequestCollector extends AbstractDataCollector
257257
{
258-
public function collect(Request $request, Response $response, \Throwable $exception = null)
258+
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
259259
{
260260
$this->data = [
261261
'method' => $request->getMethod(),

reference/constraints/File.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type. The ``Author`` class might look as follows::
4040
{
4141
protected $bioFile;
4242

43-
public function setBioFile(File $file = null)
43+
public function setBioFile(?File $file = null)
4444
{
4545
$this->bioFile = $file;
4646
}

reference/constraints/Image.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ would be a ``file`` type. The ``Author`` class might look as follows::
3535
{
3636
protected $headshot;
3737

38-
public function setHeadshot(File $file = null)
38+
public function setHeadshot(?File $file = null)
3939
{
4040
$this->headshot = $file;
4141
}

reference/forms/types/collection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ the value is removed from the collection. For example::
160160

161161
$builder->add('users', CollectionType::class, [
162162
// ...
163-
'delete_empty' => function (User $user = null) {
163+
'delete_empty' => function (?User $user = null) {
164164
return null === $user || empty($user->getFirstName());
165< 179B code>165
},
166166
]);

routing/custom_route_loader.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ you do. The resource name itself is not actually used in the example::
240240
{
241241
private $isLoaded = false;
242242

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

270-
public function supports($resource, string $type = null)
270+
public function supports($resource, ?string $type = null)
271271
{
272272
return 'extra' === $type;
273273
}
@@ -412,7 +412,7 @@ configuration file - you can call the
412412

413413
class AdvancedLoader extends Loader
414414
{
415-
public function load($resource, string $type = null)
415+
public function load($resource, ?string $type = null)
416416
{
417417
$routes = new RouteCollection();
418418

@@ -426,7 +426,7 @@ configuration file - you can call the
426426
return $routes;
427427
}
428428

429-
public function supports($resource, string $type = null)
429+
public function supports($resource, ?string $type = null)
430430
{
431431
return 'advanced_extra' === $type;
432432
}

security/access_denied_handler.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ unauthenticated user tries to access a protected resource::
4040
$this->urlGenerator = $urlGenerator;
4141
}
4242

43-
public function start(Request $request, AuthenticationException $authException = null): RedirectResponse
43+
public function start(Request $request, ?AuthenticationException $authException = null): RedirectResponse
4444
{
4545
// add a custom flash message and redirect to the login page
4646
$request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.');

security/login_link.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ This will send an email like this to the user:
312312

313313
class CustomLoginLinkNotification extends LoginLinkNotification
314314
{
315-
public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
315+
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
316316
{
317317
$emailMessage = parent::asEmailMessage($recipient, $transport);
318318

serializer/custom_normalizer.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:
3333
$this->normalizer = $normalizer;
3434
}
3535

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

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

48-
public function supportsNormalization($data, string $format = null, array $context = [])
48+
public function supportsNormalization($data, ?string $format = null, array $context = [])
4949
{
5050
return $data instanceof Topic;
5151
}

validation/custom_constraint.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ First you need to create a Constraint class and extend :class:`Symfony\\Componen
4444
public $mode = 'strict';
4545
4646
// all configurable options must be passed to the constructor
47-
public function __construct(string $mode = null, string $message = null, array $groups = null, $payload = null)
47+
public function __construct(?string $mode = null, ?string $message = null, ?array $groups = null, $payload = null)
4848
{
4949
parent::__construct([], $groups, $payload);
5050
@@ -270,9 +270,9 @@ define those options as public properties on the constraint class:
270270
271271
public function __construct(
272272
$mandatoryFooOption,
273-
string $message = null,
274-
bool $optionalBarOption = null,
275-
array $groups = null,
273+
?string $message = null,
274+
?bool $optionalBarOption = null,
275+
?array $groups = null,
276276
$payload = null,
277277
array $options = []
278278
) {

0 commit comments

Comments
 (0)
0