diff --git a/cache.rst b/cache.rst
index f9d7175cf41..fda6cdb9810 100644
--- a/cache.rst
+++ b/cache.rst
@@ -363,7 +363,7 @@ with either :class:`Symfony\\Contracts\\Cache\\CacheInterface` or
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$container->services()
// ...
diff --git a/components/options_resolver.rst b/components/options_resolver.rst
index fb459f3d9cd..91e5d742c7a 100644
--- a/components/options_resolver.rst
+++ b/components/options_resolver.rst
@@ -23,7 +23,7 @@ Imagine you have a ``Mailer`` class which has four options: ``host``,
class Mailer
{
- protected $options;
+ protected array $options;
public function __construct(array $options = [])
{
@@ -37,7 +37,7 @@ check which options are set::
class Mailer
{
// ...
- public function sendMail($from, $to)
+ public function sendMail($from, $to): void
{
$mail = ...;
@@ -884,9 +884,9 @@ can change your code to do the configuration only once per class::
// ...
class Mailer
{
- private static $resolversByClass = [];
+ private static array $resolversByClass = [];
- protected $options;
+ protected array $options;
public function __construct(array $options = [])
{
@@ -902,7 +902,7 @@ can change your code to do the configuration only once per class::
$this->options = self::$resolversByClass[$class]->resolve($options);
}
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
// ...
}
@@ -917,9 +917,9 @@ method ``clearOptionsConfig()`` and call it periodically::
// ...
class Mailer
{
- private static $resolversByClass = [];
+ private static array $resolversByClass = [];
- public static function clearOptionsConfig()
+ public static function clearOptionsConfig(): void
{
self::$resolversByClass = [];
}
diff --git a/components/serializer.rst b/components/serializer.rst
index e08bd5c1f07..007cf4818b9 100644
--- a/components/serializer.rst
+++ b/components/serializer.rst
@@ -73,7 +73,7 @@ exists in your project::
private int $age;
private string $name;
private bool $sportsperson;
- private ?\DateTime $createdAt;
+ private ?\DateTimeInterface $createdAt;
// Getters
public function getAge(): int
@@ -113,7 +113,7 @@ exists in your project::
$this->sportsperson = $sportsperson;
}
- public function setCreatedAt(\DateTime $createdAt = null): void
+ public function setCreatedAt(\DateTimeInterface $createdAt = null): void
{
$this->createdAt = $createdAt;
}
@@ -607,11 +607,11 @@ processes::
class Person
{
public function __construct(
- private $firstName,
+ private string $firstName,
) {
}
- public function getFirstName()
+ public function getFirstName(): string
{
return $this->firstName;
}
@@ -663,7 +663,7 @@ defines a ``Person`` entity with a ``firstName`` property:
{
public function __construct(
#[SerializedName('customer_name')]
- private $firstName,
+ private string $firstName,
) {
}
diff --git a/components/validator/resources.rst b/components/validator/resources.rst
index d5cfd85e297..19b0c54b6ec 100644
--- a/components/validator/resources.rst
+++ b/components/validator/resources.rst
@@ -37,9 +37,9 @@ In this example, the validation metadata is retrieved executing the
class User
{
- protected $name;
+ protected string $name;
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
$metadata->addPropertyConstraint('name', new Assert\Length([
@@ -99,7 +99,7 @@ prefixed classes included in doc block comments (``/** ... */``). For example::
/**
* @Assert\NotBlank
*/
- protected $name;
+ protected string $name;
}
To enable the annotation loader, call the
diff --git a/components/var_dumper.rst b/components/var_dumper.rst
index ccde974b9e5..c9da6873218 100644
--- a/components/var_dumper.rst
+++ b/components/var_dumper.rst
@@ -372,9 +372,9 @@ then its dump representation::
class PropertyExample
{
- public $publicProperty = 'The `+` prefix denotes public properties,';
- protected $protectedProperty = '`#` protected ones and `-` private ones.';
- private $privateProperty = 'Hovering a property shows a reminder.';
+ public string $publicProperty = 'The `+` prefix denotes public properties,';
+ protected string $protectedProperty = '`#` protected ones and `-` private ones.';
+ private string $privateProperty = 'Hovering a property shows a reminder.';
}
$var = new PropertyExample();
@@ -391,7 +391,7 @@ then its dump representation::
class DynamicPropertyExample
{
- public $declaredProperty = 'This property is declared in the class definition';
+ public string $declaredProperty = 'This property is declared in the class definition';
}
$var = new DynamicPropertyExample();
@@ -404,7 +404,7 @@ then its dump representation::
class ReferenceExample
{
- public $info = "Circular and sibling references are displayed as `#number`.\nHovering them highlights all instances in the same dump.\n";
+ public string $info = "Circular and sibling references are displayed as `#number`.\nHovering them highlights all instances in the same dump.\n";
}
$var = new ReferenceExample();
$var->aCircularReference = $var;
diff --git a/components/var_exporter.rst b/components/var_exporter.rst
index 866f97ee2ff..9c5677c91d8 100644
--- a/components/var_exporter.rst
+++ b/components/var_exporter.rst
@@ -50,10 +50,10 @@ following class hierarchy::
abstract class AbstractClass
{
- protected $foo;
- private $bar;
+ protected int $foo;
+ private int $bar;
- protected function setBar($bar)
+ protected function setBar($bar): void
{
$this->bar = $bar;
}
diff --git a/doctrine/resolve_target_entity.rst b/doctrine/resolve_target_entity.rst
index 81de0c75ff0..9c3e700e0cf 100644
--- a/doctrine/resolve_target_entity.rst
+++ b/doctrine/resolve_target_entity.rst
@@ -65,11 +65,8 @@ An Invoice entity::
#[ORM\Table(name: 'invoice')]
class Invoice
{
- /**
- * @var InvoiceSubjectInterface
- */
#[ORM\ManyToOne(targetEntity: InvoiceSubjectInterface::class)]
- protected $subject;
+ protected InvoiceSubjectInterface $subject;
}
An InvoiceSubjectInterface::
diff --git a/event_dispatcher.rst b/event_dispatcher.rst
index 275ec7863fe..896dff71d29 100644
--- a/event_dispatcher.rst
+++ b/event_dispatcher.rst
@@ -91,7 +91,7 @@ notify Symfony that it is an event listener by using a special "tag":
use App\EventListener\ExceptionListener;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(ExceptionListener::class)
diff --git a/form/bootstrap5.rst b/form/bootstrap5.rst
index c801757ea77..400747bba12 100644
--- a/form/bootstrap5.rst
+++ b/form/bootstrap5.rst
@@ -57,7 +57,7 @@ configuration:
// config/packages/twig.php
use Symfony\Config\TwigConfig;
- return static function(TwigConfig $twig) {
+ return static function(TwigConfig $twig): void {
$twig->formThemes(['bootstrap_5_layout.html.twig']);
// ...
diff --git a/form/form_collections.rst b/form/form_collections.rst
index 2fc6ddda01a..d36dce954b3 100644
--- a/form/form_collections.rst
+++ b/form/form_collections.rst
@@ -16,8 +16,8 @@ Let's start by creating a ``Task`` entity::
class Task
{
- protected $description;
- protected $tags;
+ protected string $description;
+ protected ArrayCollection $tags;
public function __construct()
{
@@ -53,7 +53,7 @@ objects::
class Tag
{
- private $name;
+ private string $name;
public function getName(): string
{
@@ -466,7 +466,7 @@ you will learn about next!).
// ...
#[ORM\ManyToMany(targetEntity: Tag::class, cascade: ['persist'])]
- protected $tags;
+ protected array $tags;
.. code-block:: yaml
diff --git a/forms.rst b/forms.rst
index 9a673dc4fc6..a00c7a94ab2 100644
--- a/forms.rst
+++ b/forms.rst
@@ -43,8 +43,9 @@ following ``Task`` class::
class Task
{
- protected $task;
- protected $dueDate;
+ protected string $task;
+
+ protected ?\DateTimeInterface $dueDate;
public function getTask(): string
{
@@ -56,12 +57,12 @@ following ``Task`` class::
$this->task = $task;
}
- public function getDueDate(): ?\DateTime
+ public function getDueDate(): ?\DateTimeInterface
{
return $this->dueDate;
}
- public function setDueDate(?\DateTime $dueDate): void
+ public function setDueDate(?\DateTimeInterface $dueDate): void
{
$this->dueDate = $dueDate;
}
@@ -128,7 +129,7 @@ use the ``createFormBuilder()`` helper::
// creates a task object and initializes some data for this example
$task = new Task();
$task->setTask('Write a blog post');
- $task->setDueDate(new \DateTime('tomorrow'));
+ $task->setDueDate(new \DateTimeImmutable('tomorrow'));
$form = $this->createFormBuilder($task)
->add('task', TextType::class)
@@ -209,7 +210,7 @@ use the ``createForm()`` helper (otherwise, use the ``create()`` method of the
// creates a task object and initializes some data for this example
$task = new Task();
$task->setTask('Write a blog post');
- $task->setDueDate(new \DateTime('tomorrow'));
+ $task->setDueDate(new \DateTimeImmutable('tomorrow'));
$form = $this->createForm(TaskType::class, $task);
@@ -471,7 +472,7 @@ to a class. You can add them either to the entity class or to the form class.
To see the first approach - adding constraints to the entity - in action,
add the validation constraints, so that the ``task`` field cannot be empty,
-and the ``dueDate`` field cannot be empty, and must be a valid ``DateTime``
+and the ``dueDate`` field cannot be empty, and must be a valid ``DateTimeImmutable``
object.
.. configuration-block::
@@ -486,11 +487,11 @@ object.
class Task
{
#[Assert\NotBlank]
- public $task;
+ public string $task;
#[Assert\NotBlank]
- #[Assert\Type(\DateTime::class)]
- protected $dueDate;
+ #[Assert\Type(\DateTimeInterface::class)]
+ protected \DateTimeInterface $dueDate;
}
.. code-block:: yaml
@@ -502,7 +503,7 @@ object.
- NotBlank: ~
dueDate:
- NotBlank: ~
- - Type: \DateTime
+ - Type: \DateTimeInterface
.. code-block:: xml
@@ -519,7 +520,7 @@ object.
- \DateTime
+ \DateTimeInterface
@@ -544,7 +545,7 @@ object.
$metadata->addPropertyConstraint('dueDate', new NotBlank());
$metadata->addPropertyConstraint(
'dueDate',
- new Type(\DateTime::class)
+ new Type(\DateTimeInterface::class)
);
}
}
diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst
index 9b86685889b..0bbcf934e58 100644
--- a/frontend/custom_version_strategy.rst
+++ b/frontend/custom_version_strategy.rst
@@ -130,7 +130,7 @@ After creating the strategy PHP class, register it as a Symfony service.
use App\Asset\VersionStrategy\GulpBusterVersionStrategy;
use Symfony\Component\DependencyInjection\Definition;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(GulpBusterVersionStrategy::class)
diff --git a/messenger/multiple_buses.rst b/messenger/multiple_buses.rst
index 7c2b548796d..8cc5fa5fa22 100644
--- a/messenger/multiple_buses.rst
+++ b/messenger/multiple_buses.rst
@@ -222,7 +222,7 @@ you can determine the message bus based on an implemented interface:
use App\MessageHandler\CommandHandlerInterface;
use App\MessageHandler\QueryHandlerInterface;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// ...
diff --git a/profiler.rst b/profiler.rst
index dbe3dc6e989..f14fdcee0a7 100644
--- a/profiler.rst
+++ b/profiler.rst
@@ -536,7 +536,7 @@ you'll need to configure the data collector explicitly:
use App\DataCollector\RequestCollector;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(RequestCollector::class)
diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst
index 7fb1428bab7..3aa05b1d2d0 100644
--- a/reference/constraints/All.rst
+++ b/reference/constraints/All.rst
@@ -31,7 +31,7 @@ entry in that array:
new Assert\NotBlank,
new Assert\Length(min: 5),
])]
- protected $favoriteColors = [];
+ protected array $favoriteColors = [];
}
.. code-block:: yaml
@@ -77,7 +77,7 @@ entry in that array:
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('favoriteColors', new Assert\All([
'constraints' => [
diff --git a/reference/constraints/AtLeastOneOf.rst b/reference/constraints/AtLeastOneOf.rst
index e3402c23b02..0a6ab618aa5 100644
--- a/reference/constraints/AtLeastOneOf.rst
+++ b/reference/constraints/AtLeastOneOf.rst
@@ -35,7 +35,7 @@ The following constraints ensure that:
new Assert\Regex('/#/'),
new Assert\Length(min: 10),
])]
- protected $plainPassword;
+ protected string $plainPassword;
#[Assert\AtLeastOneOf([
new Assert\Count(min: 3),
@@ -43,7 +43,7 @@ The following constraints ensure that:
new Assert\GreaterThanOrEqual(5)
),
])]
- protected $grades;
+ protected array $grades;
}
.. code-block:: yaml
@@ -113,7 +113,7 @@ The following constraints ensure that:
class Student
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('password', new Assert\AtLeastOneOf([
'constraints' => [
diff --git a/reference/constraints/Bic.rst b/reference/constraints/Bic.rst
index 7cc2e46f558..69ce35248f3 100644
--- a/reference/constraints/Bic.rst
+++ b/reference/constraints/Bic.rst
@@ -30,7 +30,7 @@ will contain a Business Identifier Code (BIC).
class Transaction
{
#[Assert\Bic]
- protected $businessIdentifierCode;
+ protected string $businessIdentifierCode;
}
.. code-block:: yaml
@@ -66,7 +66,7 @@ will contain a Business Identifier Code (BIC).
class Transaction
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic());
}
diff --git a/reference/constraints/Blank.rst b/reference/constraints/Blank.rst
index fe17e88e40f..485d25319ac 100644
--- a/reference/constraints/Blank.rst
+++ b/reference/constraints/Blank.rst
@@ -37,7 +37,7 @@ of an ``Author`` class were blank, you could do the following:
class Author
{
#[Assert\Blank]
- protected $firstName;
+ protected string $firstName;
}
.. code-block:: yaml
@@ -73,7 +73,7 @@ of an ``Author`` class were blank, you could do the following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\Blank());
}
diff --git a/reference/constraints/CardScheme.rst b/reference/constraints/CardScheme.rst
index 59f0d048f15..6e98e6fab98 100644
--- a/reference/constraints/CardScheme.rst
+++ b/reference/constraints/CardScheme.rst
@@ -32,7 +32,7 @@ on an object that will contain a credit card number.
schemes: [Assert\CardScheme::VISA],
message: 'Your credit card number is invalid.',
)]
- protected $cardNumber;
+ protected string $cardNumber;
}
.. code-block:: yaml
@@ -75,7 +75,7 @@ on an object that will contain a credit card number.
class Transaction
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme([
'schemes' => [
diff --git a/reference/constraints/Cascade.rst b/reference/constraints/Cascade.rst
index 5880fdd6389..aeaa4213832 100644
--- a/reference/constraints/Cascade.rst
+++ b/reference/constraints/Cascade.rst
@@ -35,7 +35,7 @@ constraints that are set in the child classes ``BookMetadata`` and
class BookCollection
{
#[Assert\NotBlank]
- protected $name = '';
+ protected string $name = '';
public BookMetadata $metadata;
@@ -76,7 +76,7 @@ constraints that are set in the child classes ``BookMetadata`` and
{
// ...
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new Assert\Cascade());
}
diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst
index b1b27bdd6fd..2ec882298ec 100644
--- a/reference/constraints/Choice.rst
+++ b/reference/constraints/Choice.rst
@@ -32,13 +32,13 @@ If your valid choice list is simple, you can pass them in directly via the
class Author
{
- const GENRES = ['fiction', 'non-fiction'];
+ public const GENRES = ['fiction', 'non-fiction'];
#[Assert\Choice(['New York', 'Berlin', 'Tokyo'])]
- protected $city;
+ protected string $city;
#[Assert\Choice(choices: Author::GENRES, message: 'Choose a valid genre.')]
- protected $genre;
+ protected string $genre;
}
.. code-block:: yaml
@@ -91,7 +91,9 @@ If your valid choice list is simple, you can pass them in directly via the
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint(
'city',
@@ -138,7 +140,7 @@ constraint.
class Author
{
#[Assert\Choice(callback: 'getGenres')]
- protected $genre;
+ protected string $genre;
}
.. code-block:: yaml
@@ -176,9 +178,9 @@ constraint.
class Author
{
- protected $genre;
+ // ...
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('genre', new Assert\Choice([
'callback' => 'getGenres',
@@ -202,7 +204,7 @@ you can pass the class name and the method as an array.
class Author
{
#[Assert\Choice(callback: [Genre::class, 'getGenres'])]
- protected $genre;
+ protected string $genre;
}
.. code-block:: yaml
@@ -244,7 +246,9 @@ you can pass the class name and the method as an array.
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('genre', new Assert\Choice([
'callback' => [Genre::class, 'getGenres'],
diff --git a/reference/constraints/Cidr.rst b/reference/constraints/Cidr.rst
index 31080ab1abb..d7bc9e6b4a0 100644
--- a/reference/constraints/Cidr.rst
+++ b/reference/constraints/Cidr.rst
@@ -27,7 +27,7 @@ Basic Usage
class NetworkSettings
{
#[Assert\Cidr]
- protected $cidrNotation;
+ protected string $cidrNotation;
}
.. code-block:: yaml
@@ -63,7 +63,9 @@ Basic Usage
class NetworkSettings
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('cidrNotation', new Assert\Cidr());
}
diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst
index de29e9837ea..2d16d201b17 100644
--- a/reference/constraints/Collection.rst
+++ b/reference/constraints/Collection.rst
@@ -33,12 +33,12 @@ of a collection individually. Take the following example::
class Author
{
- protected $profileData = [
+ protected array $profileData = [
'personal_email' => '...',
'short_bio' => '...',
];
- public function setProfileData($key, $value)
+ public function setProfileData($key, $value): void
{
$this->profileData[$key] = $value;
}
@@ -73,7 +73,7 @@ following:
],
allowMissingFields: true,
)]
- protected $profileData = [
+ protected array $profileData = [
'personal_email' => '...',
'short_bio' => '...',
];
@@ -135,7 +135,9 @@ following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
'fields' => [
@@ -203,7 +205,7 @@ you can do the following:
),
],
)]
- protected $profileData = ['personal_email' => 'email@example.com'];
+ protected array $profileData = ['personal_email' => 'email@example.com'];
}
.. code-block:: yaml
@@ -261,9 +263,9 @@ you can do the following:
class Author
{
- protected $profileData = ['personal_email'];
+ // ...
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('profileData', new Assert\Collection([
'fields' => [
diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst
index c460028df37..0bf40aca8e9 100644
--- a/reference/constraints/Count.rst
+++ b/reference/constraints/Count.rst
@@ -33,7 +33,7 @@ you might add the following:
minMessage: 'You must specify at least one email',
maxMessage: 'You cannot specify more than {{ limit }} emails',
)]
- protected $emails = [];
+ protected array $emails = [];
}
.. code-block:: yaml
@@ -78,7 +78,9 @@ you might add the following:
class Participant
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('emails', new Assert\Count([
'min' => 1,
diff --git a/reference/constraints/Country.rst b/reference/constraints/Country.rst
index 5a47a7cae44..70aae5d3cc5 100644
--- a/reference/constraints/Country.rst
+++ b/reference/constraints/Country.rst
@@ -24,7 +24,7 @@ Basic Usage
class User
{
#[Assert\Country]
- protected $country;
+ protected string $country;
}
.. code-block:: yaml
@@ -60,7 +60,9 @@ Basic Usage
class User
{
- public static function loadValidationMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidationMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('country', new Assert\Country());
}
diff --git a/reference/constraints/CssColor.rst b/reference/constraints/CssColor.rst
index 383c112fa85..88a4eb4be9f 100644
--- a/reference/constraints/CssColor.rst
+++ b/reference/constraints/CssColor.rst
@@ -31,19 +31,19 @@ the named CSS colors:
class Bulb
{
#[Assert\CssColor]
- protected $defaultColor;
+ protected string $defaultColor;
#[Assert\CssColor(
formats: Assert\CssColor::HEX_LONG,
message: 'The accent color must be a 6-character hexadecimal color.',
)]
- protected $accentColor;
+ protected string $accentColor;
#[Assert\CssColor(
formats: [Assert\CssColor::BASIC_NAMED_COLORS, Assert\CssColor::EXTENDED_NAMED_COLORS],
message: 'The color '{{ value }}' is not a valid CSS color name.',
)]
- protected $currentColor;
+ protected string $currentColor;
}
.. code-block:: yaml
@@ -104,7 +104,9 @@ the named CSS colors:
class Bulb
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('defaultColor', new Assert\CssColor());
diff --git a/reference/constraints/Currency.rst b/reference/constraints/Currency.rst
index ccf1a2928bf..cf074d4b069 100644
--- a/reference/constraints/Currency.rst
+++ b/reference/constraints/Currency.rst
@@ -27,7 +27,7 @@ a valid currency, you could do the following:
class Order
{
#[Assert\Currency]
- protected $currency;
+ protected string $currency;
}
.. code-block:: yaml
@@ -63,7 +63,9 @@ a valid currency, you could do the following:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('currency', new Assert\Currency());
}
diff --git a/reference/constraints/Date.rst b/reference/constraints/Date.rst
index c011bdedd13..93bd401cff6 100644
--- a/reference/constraints/Date.rst
+++ b/reference/constraints/Date.rst
@@ -25,7 +25,7 @@ Basic Usage
class Author
{
#[Assert\Date]
- protected $birthday;
+ protected string $birthday;
}
.. code-block:: yaml
@@ -64,9 +64,9 @@ Basic Usage
/**
* @var string A "Y-m-d" formatted value
*/
- protected $birthday;
+ protected string $birthday;
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('birthday', new Assert\Date());
}
diff --git a/reference/constraints/DateTime.rst b/reference/constraints/DateTime.rst
index 39ca4e3a5a1..f6bcce7e5f5 100644
--- a/reference/constraints/DateTime.rst
+++ b/reference/constraints/DateTime.rst
@@ -28,7 +28,7 @@ Basic Usage
* @var string A "Y-m-d H:i:s" formatted value
*/
#[Assert\DateTime]
- protected $createdAt;
+ protected string $createdAt;
}
.. code-block:: yaml
@@ -67,9 +67,9 @@ Basic Usage
/**
* @var string A "Y-m-d H:i:s" formatted value
*/
- protected $createdAt;
+ protected string $createdAt;
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('createdAt', new Assert\DateTime());
}
diff --git a/reference/constraints/DivisibleBy.rst b/reference/constraints/DivisibleBy.rst
index 19f69414dd5..dd90ad9a0fd 100644
--- a/reference/constraints/DivisibleBy.rst
+++ b/reference/constraints/DivisibleBy.rst
@@ -35,12 +35,12 @@ The following constraints ensure that:
class Item
{
#[Assert\DivisibleBy(0.25)]
- protected $weight;
+ protected float $weight;
#[Assert\DivisibleBy(
value: 5,
)]
- protected $quantity;
+ protected int $quantity;
}
.. code-block:: yaml
@@ -86,7 +86,9 @@ The following constraints ensure that:
class Item
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('weight', new Assert\DivisibleBy(0.25));
diff --git a/reference/constraints/Email.rst b/reference/constraints/Email.rst
index 3dc98946638..19b1579b88a 100644
--- a/reference/constraints/Email.rst
+++ b/reference/constraints/Email.rst
@@ -27,7 +27,7 @@ Basic Usage
#[Assert\Email(
message: 'The email {{ value }} is not a valid email.',
)]
- protected $email;
+ protected string $email;
}
.. code-block:: yaml
@@ -66,7 +66,9 @@ Basic Usage
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('email', new Assert\Email([
'message' => 'The email "{{ value }}" is not a valid email.',
diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst
index 41e95947963..0c2db8e5b4e 100644
--- a/reference/constraints/EqualTo.rst
+++ b/reference/constraints/EqualTo.rst
@@ -35,12 +35,12 @@ and that the ``age`` is ``20``, you could do the following:
class Person
{
#[Assert\EqualTo('Mary')]
- protected $firstName;
+ protected string $firstName;
#[Assert\EqualTo(
value: 20,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -86,7 +86,9 @@ and that the ``age`` is ``20``, you could do the following:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\EqualTo('Mary'));
diff --git a/reference/constraints/ExpressionLanguageSyntax.rst b/reference/constraints/ExpressionLanguageSyntax.rst
index 3ce3850979b..f10956c4046 100644
--- a/reference/constraints/ExpressionLanguageSyntax.rst
+++ b/reference/constraints/ExpressionLanguageSyntax.rst
@@ -37,12 +37,12 @@ The following constraints ensure that:
class Order
{
#[Assert\ExpressionLanguageSyntax]
- protected $promotion;
+ protected string $promotion;
#[Assert\ExpressionLanguageSyntax(
allowedVariables: ['user', 'shipping_centers'],
)]
- protected $shippingOptions;
+ protected string $shippingOptions;
}
.. code-block:: yaml
@@ -89,7 +89,9 @@ The following constraints ensure that:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('promotion', new Assert\ExpressionLanguageSyntax());
diff --git a/reference/constraints/ExpressionSyntax.rst b/reference/constraints/ExpressionSyntax.rst
index 45a633867d7..2a603eaa616 100644
--- a/reference/constraints/ExpressionSyntax.rst
+++ b/reference/constraints/ExpressionSyntax.rst
@@ -38,12 +38,12 @@ The following constraints ensure that:
class Order
{
#[Assert\ExpressionSyntax]
- protected $promotion;
+ protected string $promotion;
#[Assert\ExpressionSyntax(
allowedVariables: ['user', 'shipping_centers'],
)]
- protected $shippingOptions;
+ protected string $shippingOptions;
}
.. code-block:: yaml
@@ -90,7 +90,9 @@ The following constraints ensure that:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('promotion', new Assert\ExpressionSyntax());
diff --git a/reference/constraints/File.rst b/reference/constraints/File.rst
index 44503da656f..68a65dfba20 100644
--- a/reference/constraints/File.rst
+++ b/reference/constraints/File.rst
@@ -38,14 +38,14 @@ type. The ``Author`` class might look as follows::
class Author
{
- protected $bioFile;
+ protected File $bioFile;
- public function setBioFile(File $file = null)
+ public function setBioFile(File $file = null): void
{
$this->bioFile = $file;
}
- public function getBioFile()
+ public function getBioFile(): File
{
return $this->bioFile;
}
@@ -70,7 +70,7 @@ below a certain file size and a valid PDF, add the following:
extensions: ['pdf'],
extensionsMessage: 'Please upload a valid PDF',
)]
- protected $bioFile;
+ protected File $bioFile;
}
.. code-block:: yaml
@@ -115,7 +115,9 @@ below a certain file size and a valid PDF, add the following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bioFile', new Assert\File([
'maxSize' => '1024k',
diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst
index 3695486491c..4f2e34bcbfa 100644
--- a/reference/constraints/GreaterThan.rst
+++ b/reference/constraints/GreaterThan.rst
@@ -32,12 +32,12 @@ The following constraints ensure that:
class Person
{
#[Assert\GreaterThan(5)]
- protected $siblings;
+ protected int $siblings;
#[Assert\GreaterThan(
value: 18,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -83,7 +83,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('siblings', new Assert\GreaterThan(5));
@@ -112,7 +114,7 @@ that a date must at least be the next day:
class Order
{
#[Assert\GreaterThan('today')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -148,7 +150,9 @@ that a date must at least be the next day:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('today'));
}
@@ -169,7 +173,7 @@ dates. If you want to fix the timezone, append it to the date string:
class Order
{
#[Assert\GreaterThan('today UTC')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -205,7 +209,9 @@ dates. If you want to fix the timezone, append it to the date string:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('today UTC'));
}
@@ -227,7 +233,7 @@ current time:
class Order
{
#[Assert\GreaterThan('+5 hours')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -263,7 +269,9 @@ current time:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThan('+5 hours'));
}
diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst
index 0adb729eae7..e5a71e5f788 100644
--- a/reference/constraints/GreaterThanOrEqual.rst
+++ b/reference/constraints/GreaterThanOrEqual.rst
@@ -31,12 +31,12 @@ The following constraints ensure that:
class Person
{
#[Assert\GreaterThanOrEqual(5)]
- protected $siblings;
+ protected int $siblings;
#[Assert\GreaterThanOrEqual(
value: 18,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -82,7 +82,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('siblings', new Assert\GreaterThanOrEqual(5));
@@ -111,7 +113,7 @@ that a date must at least be the current day:
class Order
{
#[Assert\GreaterThanOrEqual('today')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -147,7 +149,9 @@ that a date must at least be the current day:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('today'));
}
@@ -168,7 +172,7 @@ dates. If you want to fix the timezone, append it to the date string:
class Order
{
#[Assert\GreaterThanOrEqual('today UTC')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -204,7 +208,9 @@ dates. If you want to fix the timezone, append it to the date string:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('today UTC'));
}
@@ -226,7 +232,7 @@ current time:
class Order
{
#[Assert\GreaterThanOrEqual('+5 hours')]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -262,7 +268,9 @@ current time:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\GreaterThanOrEqual('+5 hours'));
}
diff --git a/reference/constraints/Hostname.rst b/reference/constraints/Hostname.rst
index eea851b144f..95b10d1736e 100644
--- a/reference/constraints/Hostname.rst
+++ b/reference/constraints/Hostname.rst
@@ -29,7 +29,7 @@ will contain a host name.
class ServerSettings
{
#[Assert\Hostname(message: 'The server name must be a valid hostname.')]
- protected $name;
+ protected string $name;
}
.. code-block:: yaml
@@ -68,7 +68,9 @@ will contain a host name.
class ServerSettings
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('name', new Assert\Hostname([
'message' => 'The server name must be a valid hostname.',
diff --git a/reference/constraints/Iban.rst b/reference/constraints/Iban.rst
index d7f5b7c4140..3cf800200e2 100644
--- a/reference/constraints/Iban.rst
+++ b/reference/constraints/Iban.rst
@@ -32,7 +32,7 @@ will contain an International Bank Account Number.
#[Assert\Iban(
message: 'This is not a valid International Bank Account Number (IBAN).',
)]
- protected $bankAccountNumber;
+ protected string $bankAccountNumber;
}
.. code-block:: yaml
@@ -73,9 +73,9 @@ will contain an International Bank Account Number.
class Transaction
{
- protected $bankAccountNumber;
+ // ...
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bankAccountNumber', new Assert\Iban([
'message' => 'This is not a valid International Bank Account Number (IBAN).',
diff --git a/reference/constraints/IdenticalTo.rst b/reference/constraints/IdenticalTo.rst
index 1b3c9a357e9..507493b63d4 100644
--- a/reference/constraints/IdenticalTo.rst
+++ b/reference/constraints/IdenticalTo.rst
@@ -37,12 +37,12 @@ The following constraints ensure that:
class Person
{
#[Assert\IdenticalTo('Mary')]
- protected $firstName;
+ protected string $firstName;
#[Assert\IdenticalTo(
value: 20,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -88,7 +88,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\IdenticalTo('Mary'));
diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst
index eff1ec8c4c4..22a7bc1a688 100644
--- a/reference/constraints/Image.rst
+++ b/reference/constraints/Image.rst
@@ -33,14 +33,14 @@ would be a ``file`` type. The ``Author`` class might look as follows::
class Author
{
- protected $headshot;
+ protected File $headshot;
- public function setHeadshot(File $file = null)
+ public function setHeadshot(File $file = null): void
{
$this->headshot = $file;
}
- public function getHeadshot()
+ public function getHeadshot(): File
{
return $this->headshot;
}
@@ -56,6 +56,7 @@ that it is between a certain size, add the following:
// src/Entity/Author.php
namespace App\Entity;
+ use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
class Author
@@ -66,7 +67,7 @@ that it is between a certain size, add the following:
minHeight: 200,
maxHeight: 400,
)]
- protected $headshot;
+ protected File $headshot;
}
.. code-block:: yaml
@@ -111,7 +112,9 @@ that it is between a certain size, add the following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('headshot', new Assert\Image([
'minWidth' => 200,
@@ -136,6 +139,7 @@ following code:
// src/Entity/Author.php
namespace App\Entity;
+ use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
class Author
@@ -144,7 +148,7 @@ following code:
allowLandscape: false,
allowPortrait: false,
)]
- protected $headshot;
+ protected File $headshot;
}
.. code-block:: yaml
@@ -179,7 +183,9 @@ following code:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('headshot', new Assert\Image([
'allowLandscape' => false,
diff --git a/reference/constraints/Ip.rst b/reference/constraints/Ip.rst
index c3719800d1e..2f05f677601 100644
--- a/reference/constraints/Ip.rst
+++ b/reference/constraints/Ip.rst
@@ -26,7 +26,7 @@ Basic Usage
class Author
{
#[Assert\Ip]
- protected $ipAddress;
+ protected string $ipAddress;
}
.. code-block:: yaml
@@ -62,7 +62,9 @@ Basic Usage
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('ipAddress', new Assert\Ip());
}
diff --git a/reference/constraints/IsFalse.rst b/reference/constraints/IsFalse.rst
index 05a1cd1c401..0b9ebe77491 100644
--- a/reference/constraints/IsFalse.rst
+++ b/reference/constraints/IsFalse.rst
@@ -21,11 +21,11 @@ but is most commonly useful in the latter case. For example, suppose that
you want to guarantee that some ``state`` property is *not* in a dynamic
``invalidStates`` array. First, you'd create a "getter" method::
- protected $state;
+ protected string $state;
- protected $invalidStates = [];
+ protected array $invalidStates = [];
- public function isStateInvalid()
+ public function isStateInvalid(): bool
{
return in_array($this->state, $this->invalidStates);
}
@@ -47,7 +47,7 @@ method returns **false**:
#[Assert\IsFalse(
message: "You've entered an invalid state."
)]
- public function isStateInvalid()
+ public function isStateInvalid(): bool
{
// ...
}
@@ -89,14 +89,16 @@ method returns **false**:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse([
'message' => "You've entered an invalid state.",
]));
}
- public function isStateInvalid()
+ public function isStateInvalid(): bool
{
// ...
}
diff --git a/reference/constraints/IsNull.rst b/reference/constraints/IsNull.rst
index 107ac662870..0f9726110ba 100644
--- a/reference/constraints/IsNull.rst
+++ b/reference/constraints/IsNull.rst
@@ -31,7 +31,7 @@ of an ``Author`` class exactly equal to ``null``, you could do the following:
class Author
{
#[Assert\IsNull]
- protected $firstName;
+ protected ?string $firstName = null;
}
.. code-block:: yaml
@@ -67,7 +67,9 @@ of an ``Author`` class exactly equal to ``null``, you could do the following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', Assert\IsNull());
}
diff --git a/reference/constraints/IsTrue.rst b/reference/constraints/IsTrue.rst
index f1700f599d1..678371f6e69 100644
--- a/reference/constraints/IsTrue.rst
+++ b/reference/constraints/IsTrue.rst
@@ -25,11 +25,11 @@ you have the following method::
class Author
{
- protected $token;
+ protected string $token;
- public function isTokenValid()
+ public function isTokenValid(): bool
{
- return $this->token == $this->generateToken();
+ return $this->token === $this->generateToken();
}
}
@@ -46,13 +46,15 @@ Then you can validate this method with ``IsTrue`` as follows:
class Author
{
- protected $token;
+ protected string $token;
#[Assert\IsTrue(message: 'The token is invalid.')]
- public function isTokenValid()
+ public function isTokenValid(): bool
{
- return $this->token == $this->generateToken();
+ return $this->token === $this->generateToken();
}
+
+ // ...
}
.. code-block:: yaml
@@ -91,17 +93,21 @@ Then you can validate this method with ``IsTrue`` as follows:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addGetterConstraint('tokenValid', new IsTrue([
'message' => 'The token is invalid.',
]));
}
- public function isTokenValid()
+ public function isTokenValid(): bool
{
- return $this->token == $this->generateToken();
+ return $this->token === $this->generateToken();
}
+
+ // ...
}
If the ``isTokenValid()`` returns false, the validation will fail.
diff --git a/reference/constraints/Isbn.rst b/reference/constraints/Isbn.rst
index 0152abdde55..954bff233d5 100644
--- a/reference/constraints/Isbn.rst
+++ b/reference/constraints/Isbn.rst
@@ -31,7 +31,7 @@ on an object that will contain an ISBN.
type: Assert\Isbn::ISBN_10,
message: 'This value is not valid.',
)]
- protected $isbn;
+ protected string $isbn;
}
.. code-block:: yaml
@@ -72,7 +72,9 @@ on an object that will contain an ISBN.
class Book
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('isbn', new Assert\Isbn([
'type' => Assert\Isbn::ISBN_10,
diff --git a/reference/constraints/Isin.rst b/reference/constraints/Isin.rst
index 8f06a003f0f..d611cf60898 100644
--- a/reference/constraints/Isin.rst
+++ b/reference/constraints/Isin.rst
@@ -25,7 +25,7 @@ Basic Usage
class UnitAccount
{
#[Assert\Isin]
- protected $isin;
+ protected string $isin;
}
.. code-block:: yaml
@@ -61,7 +61,9 @@ Basic Usage
class UnitAccount
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('isin', new Assert\Isin());
}
diff --git a/reference/constraints/Issn.rst b/reference/constraints/Issn.rst
index 6e934dcdc2f..fa2fbae5bf5 100644
--- a/reference/constraints/Issn.rst
+++ b/reference/constraints/Issn.rst
@@ -25,7 +25,7 @@ Basic Usage
class Journal
{
#[Assert\Issn]
- protected $issn;
+ protected string $issn;
}
.. code-block:: yaml
@@ -61,7 +61,9 @@ Basic Usage
class Journal
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('issn', new Assert\Issn());
}
diff --git a/reference/constraints/Language.rst b/reference/constraints/Language.rst
index 6b52d2ef6ae..e3752c4d47f 100644
--- a/reference/constraints/Language.rst
+++ b/reference/constraints/Language.rst
@@ -25,7 +25,7 @@ Basic Usage
class User
{
#[Assert\Language]
- protected $preferredLanguage;
+ protected string $preferredLanguage;
}
.. code-block:: yaml
@@ -61,7 +61,9 @@ Basic Usage
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('preferredLanguage', new Assert\Language());
}
diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst
index 89e8b02547d..b653d2bea23 100644
--- a/reference/constraints/Length.rst
+++ b/reference/constraints/Length.rst
@@ -32,7 +32,7 @@ and ``50``, you might add the following:
minMessage: 'Your first name must be at least {{ limit }} characters long',
maxMessage: 'Your first name cannot be longer than {{ limit }} characters',
)]
- protected $firstName;
+ protected string $firstName;
}
@@ -82,7 +82,9 @@ and ``50``, you might add the following:
class Participant
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\Length([
'min' => 2,
diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst
index 913624e46d8..964bfbb3527 100644
--- a/reference/constraints/LessThan.rst
+++ b/reference/constraints/LessThan.rst
@@ -32,12 +32,12 @@ The following constraints ensure that:
class Person
{
#[Assert\LessThan(5)]
- protected $siblings;
+ protected int $siblings;
#[Assert\LessThan(
value: 80,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -83,7 +83,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('siblings', new Assert\LessThan(5));
@@ -112,7 +114,7 @@ that a date must be in the past like this:
class Person
{
#[Assert\LessThan('today')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -148,7 +150,9 @@ that a date must be in the past like this:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThan('today'));
}
@@ -169,7 +173,7 @@ dates. If you want to fix the timezone, append it to the date string:
class Person
{
#[Assert\LessThan('today UTC')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -205,7 +209,9 @@ dates. If you want to fix the timezone, append it to the date string:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('age', new Assert\LessThan('today UTC'));
}
@@ -226,7 +232,7 @@ can check that a person must be at least 18 years old like this:
class Person
{
#[Assert\LessThan('-18 years')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -262,7 +268,9 @@ can check that a person must be at least 18 years old like this:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThan('-18 years'));
}
diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst
index 91f5e50b6f4..9420c3e4376 100644
--- a/reference/constraints/LessThanOrEqual.rst
+++ b/reference/constraints/LessThanOrEqual.rst
@@ -31,12 +31,12 @@ The following constraints ensure that:
class Person
{
#[Assert\LessThanOrEqual(5)]
- protected $siblings;
+ protected int $siblings;
#[Assert\LessThanOrEqual(
value: 80,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -82,7 +82,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('siblings', new Assert\LessThanOrEqual(5));
@@ -111,7 +113,7 @@ that a date must be today or in the past like this:
class Person
{
#[Assert\LessThanOrEqual('today')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -147,7 +149,9 @@ that a date must be today or in the past like this:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThanOrEqual('today'));
}
@@ -168,7 +172,7 @@ dates. If you want to fix the timezone, append it to the date string:
class Person
{
#[Assert\LessThanOrEqual('today UTC')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -204,7 +208,9 @@ dates. If you want to fix the timezone, append it to the date string:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThanOrEqual('today UTC'));
}
@@ -225,7 +231,7 @@ can check that a person must be at least 18 years old like this:
class Person
{
#[Assert\LessThanOrEqual('-18 years')]
- protected $dateOfBirth;
+ protected \DateTimeInterface $dateOfBirth;
}
.. code-block:: yaml
@@ -261,7 +267,9 @@ can check that a person must be at least 18 years old like this:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('dateOfBirth', new Assert\LessThanOrEqual('-18 years'));
}
diff --git a/reference/constraints/Locale.rst b/reference/constraints/Locale.rst
index f1c5b91627d..49edd473d05 100644
--- a/reference/constraints/Locale.rst
+++ b/reference/constraints/Locale.rst
@@ -35,7 +35,7 @@ Basic Usage
#[Assert\Locale(
canonicalize: true,
)]
- protected $locale;
+ protected string $locale;
}
.. code-block:: yaml
@@ -74,7 +74,9 @@ Basic Usage
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('locale', new Assert\Locale([
'canonicalize' => true,
diff --git a/reference/constraints/Luhn.rst b/reference/constraints/Luhn.rst
index f89064030a6..8f5ef34c4ba 100644
--- a/reference/constraints/Luhn.rst
+++ b/reference/constraints/Luhn.rst
@@ -29,7 +29,7 @@ will contain a credit card number.
class Transaction
{
#[Assert\Luhn(message: 'Please check your credit card number.')]
- protected $cardNumber;
+ protected string $cardNumber;
}
.. code-block:: yaml
@@ -68,7 +68,9 @@ will contain a credit card number.
class Transaction
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('cardNumber', new Assert\Luhn([
'message' => 'Please check your credit card number',
diff --git a/reference/constraints/Negative.rst b/reference/constraints/Negative.rst
index 388a13fb222..493ffa72beb 100644
--- a/reference/constraints/Negative.rst
+++ b/reference/constraints/Negative.rst
@@ -29,7 +29,7 @@ The following constraint ensures that the ``withdraw`` of a bank account
class TransferItem
{
#[Assert\Negative]
- protected $withdraw;
+ protected int $withdraw;
}
.. code-block:: yaml
@@ -65,7 +65,9 @@ The following constraint ensures that the ``withdraw`` of a bank account
class TransferItem
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('withdraw', new Assert\Negative());
}
diff --git a/reference/constraints/NegativeOrZero.rst b/reference/constraints/NegativeOrZero.rst
index be6f3bc7566..a6a61862b99 100644
--- a/reference/constraints/NegativeOrZero.rst
+++ b/reference/constraints/NegativeOrZero.rst
@@ -28,7 +28,7 @@ is a negative number or equal to zero:
class UnderGroundGarage
{
#[Assert\NegativeOrZero]
- protected $level;
+ protected int $level;
}
.. code-block:: yaml
@@ -64,7 +64,9 @@ is a negative number or equal to zero:
class UnderGroundGarage
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('level', new Assert\NegativeOrZero());
}
diff --git a/reference/constraints/NotBlank.rst b/reference/constraints/NotBlank.rst
index 6cf4770f21f..388206e34bd 100644
--- a/reference/constraints/NotBlank.rst
+++ b/reference/constraints/NotBlank.rst
@@ -30,7 +30,7 @@ class were not blank, you could do the following:
class Author
{
#[Assert\NotBlank]
- protected $firstName;
+ protected string $firstName;
}
.. code-block:: yaml
@@ -66,7 +66,9 @@ class were not blank, you could do the following:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\NotBlank());
}
diff --git a/reference/constraints/NotCompromisedPassword.rst b/reference/constraints/NotCompromisedPassword.rst
index 0e4bf194e68..6641f9d8cb2 100644
--- a/reference/constraints/NotCompromisedPassword.rst
+++ b/reference/constraints/NotCompromisedPassword.rst
@@ -28,7 +28,7 @@ The following constraint ensures that the ``rawPassword`` property of the
class User
{
#[Assert\NotCompromisedPassword]
- protected $rawPassword;
+ protected string $rawPassword;
}
.. code-block:: yaml
@@ -64,7 +64,9 @@ The following constraint ensures that the ``rawPassword`` property of the
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('rawPassword', new Assert\NotCompromisedPassword());
}
diff --git a/reference/constraints/NotEqualTo.rst b/reference/constraints/NotEqualTo.rst
index e957971ade0..37b03c35907 100644
--- a/reference/constraints/NotEqualTo.rst
+++ b/reference/constraints/NotEqualTo.rst
@@ -36,12 +36,12 @@ the following:
class Person
{
#[Assert\NotEqualTo('Mary')]
- protected $firstName;
+ protected string $firstName;
#[Assert\NotEqualTo(
value: 15,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -87,7 +87,9 @@ the following:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\NotEqualTo('Mary'));
diff --git a/reference/constraints/NotIdenticalTo.rst b/reference/constraints/NotIdenticalTo.rst
index c95a791a7bb..ba28fdb7c45 100644
--- a/reference/constraints/NotIdenticalTo.rst
+++ b/reference/constraints/NotIdenticalTo.rst
@@ -37,12 +37,12 @@ The following constraints ensure that:
class Person
{
#[Assert\NotIdenticalTo('Mary')]
- protected $firstName;
+ protected string $firstName;
#[Assert\NotIdenticalTo(
value: 15,
)]
- protected $age;
+ protected int $age;
}
.. code-block:: yaml
@@ -88,7 +88,9 @@ The following constraints ensure that:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('age', new Assert\NotIdenticalTo('Mary'));
diff --git a/reference/constraints/NotNull.rst b/reference/constraints/NotNull.rst
index ff0f8eaf27a..f1a27bd6560 100644
--- a/reference/constraints/NotNull.rst
+++ b/reference/constraints/NotNull.rst
@@ -29,7 +29,7 @@ class were not strictly equal to ``null``, you would:
class Author
{
#[Assert\NotNull]
- protected $firstName;
+ protected string $firstName;
}
.. code-block:: yaml
@@ -65,7 +65,9 @@ class were not strictly equal to ``null``, you would:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\NotNull());
}
diff --git a/reference/constraints/Positive.rst b/reference/constraints/Positive.rst
index 523a03be65c..d2e6adc30d7 100644
--- a/reference/constraints/Positive.rst
+++ b/reference/constraints/Positive.rst
@@ -29,7 +29,7 @@ positive number (greater than zero):
class Employee
{
#[Assert\Positive]
- protected $income;
+ protected int $income;
}
.. code-block:: yaml
@@ -66,7 +66,9 @@ positive number (greater than zero):
class Employee
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('income', new Assert\Positive());
}
diff --git a/reference/constraints/PositiveOrZero.rst b/reference/constraints/PositiveOrZero.rst
index 7596bdf3e50..4aa8420993c 100644
--- a/reference/constraints/PositiveOrZero.rst
+++ b/reference/constraints/PositiveOrZero.rst
@@ -28,7 +28,7 @@ is positive or zero:
class Person
{
#[Assert\PositiveOrZero]
- protected $siblings;
+ protected int $siblings;
}
.. code-block:: yaml
@@ -64,7 +64,9 @@ is positive or zero:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('siblings', new Assert\PositiveOrZero());
}
diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst
index 4846c01fd2c..edd199c48b9 100644
--- a/reference/constraints/Range.rst
+++ b/reference/constraints/Range.rst
@@ -31,7 +31,7 @@ you might add the following:
max: 180,
notInRangeMessage: 'You must be between {{ min }}cm and {{ max }}cm tall to enter',
)]
- protected $height;
+ protected int $height;
}
.. code-block:: yaml
@@ -74,7 +74,9 @@ you might add the following:
class Participant
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('height', new Assert\Range([
'min' => 120,
@@ -107,7 +109,7 @@ date must lie within the current year like this:
min: 'first day of January',
max: 'first day of January next year',
)]
- protected $startDate;
+ protected \DateTimeInterface $startDate;
}
.. code-block:: yaml
@@ -148,7 +150,9 @@ date must lie within the current year like this:
class Event
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('startDate', new Assert\Range([
'min' => 'first day of January',
@@ -175,7 +179,7 @@ dates. If you want to fix the timezone, append it to the date string:
min: 'first day of January UTC',
max: 'first day of January next year UTC',
)]
- protected $startDate;
+ protected \DateTimeInterface $startDate;
}
.. code-block:: yaml
@@ -216,7 +220,9 @@ dates. If you want to fix the timezone, append it to the date string:
class Event
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('startDate', new Assert\Range([
'min' => 'first day of January UTC',
@@ -243,7 +249,7 @@ can check that a delivery date starts within the next five hours like this:
min: 'now',
max: '+5 hours',
)]
- protected $deliveryDate;
+ protected \DateTimeInterface $deliveryDate;
}
.. code-block:: yaml
@@ -284,7 +290,9 @@ can check that a delivery date starts within the next five hours like this:
class Order
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('deliveryDate', new Assert\Range([
'min' => 'now',
diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst
index abfc30a9343..1028c005ab1 100644
--- a/reference/constraints/Regex.rst
+++ b/reference/constraints/Regex.rst
@@ -29,7 +29,7 @@ more word characters at the beginning of your string:
class Author
{
#[Assert\Regex('/^\w+/')]
- protected $description;
+ protected string $description;
}
.. code-block:: yaml
@@ -67,7 +67,9 @@ more word characters at the beginning of your string:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('description', new Assert\Regex([
'pattern' => '/^\w+/',
@@ -96,7 +98,7 @@ it a custom message:
match: false,
message: 'Your name cannot contain a number',
)]
- protected $firstName;
+ protected string $firstName;
}
.. code-block:: yaml
@@ -139,7 +141,9 @@ it a custom message:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\Regex([
'pattern' => '/\d/',
@@ -187,7 +191,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
pattern: '/^[a-z]+$/i',
htmlPattern: '^[a-zA-Z]+$'
)]
- protected $name;
+ protected string $name;
}
.. code-block:: yaml
@@ -228,7 +232,9 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option:
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('name', new Assert\Regex([
'pattern' => '/^[a-z]+$/i',
diff --git a/reference/constraints/Sequentially.rst b/reference/constraints/Sequentially.rst
index 950b5e81426..7620997f0a3 100644
--- a/reference/constraints/Sequentially.rst
+++ b/reference/constraints/Sequentially.rst
@@ -53,7 +53,7 @@ You can validate each of these constraints sequentially to solve these issues:
new Assert\Regex(Place::ADDRESS_REGEX),
new AcmeAssert\Geolocalizable,
])]
- public $address;
+ public string $address;
}
.. code-block:: yaml
@@ -105,7 +105,7 @@ You can validate each of these constraints sequentially to solve these issues:
class Place
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('address', new Assert\Sequentially([
new Assert\NotNull(),
diff --git a/reference/constraints/Time.rst b/reference/constraints/Time.rst
index 9b9f4af4c73..8b69d2c3b00 100644
--- a/reference/constraints/Time.rst
+++ b/reference/constraints/Time.rst
@@ -31,7 +31,7 @@ of the day when the event starts:
* @var string A "H:i:s" formatted value
*/
#[Assert\Time]
- protected $startsAt;
+ protected string $startsAt;
}
.. code-block:: yaml
@@ -70,9 +70,9 @@ of the day when the event starts:
/**
* @var string A "H:i:s" formatted value
*/
- protected $startsAt;
+ protected string $startsAt;
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('startsAt', new Assert\Time());
}
diff --git a/reference/constraints/Timezone.rst b/reference/constraints/Timezone.rst
index e410c5dee90..ffc1cee9fdd 100644
--- a/reference/constraints/Timezone.rst
+++ b/reference/constraints/Timezone.rst
@@ -27,7 +27,7 @@ string which contains any of the `PHP timezone identifiers`_ (e.g. ``America/New
class UserSettings
{
#[Assert\Timezone]
- protected $timezone;
+ protected string $timezone;
}
.. code-block:: yaml
@@ -63,7 +63,9 @@ string which contains any of the `PHP timezone identifiers`_ (e.g. ``America/New
class UserSettings
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('timezone', new Assert\Timezone());
}
diff --git a/reference/constraints/Traverse.rst b/reference/constraints/Traverse.rst
index b39431e2304..0f92c9cce54 100644
--- a/reference/constraints/Traverse.rst
+++ b/reference/constraints/Traverse.rst
@@ -39,13 +39,13 @@ that all have constraints on their properties.
*/
#[ORM\Column]
#[Assert\NotBlank]
- protected $name = '';
+ protected string $name = '';
/**
* @var Collection|Book[]
*/
#[ORM\ManyToMany(targetEntity: Book::class)]
- protected $books;
+ protected ArrayCollection $books;
// some other properties
@@ -77,7 +77,7 @@ that all have constraints on their properties.
// neither the method above nor any other specific getter
// could be used to validated all nested books;
// this object needs to be traversed to call the iterator
- public function getIterator()
+ public function getIterator(): \Iterator
{
return $this->books->getIterator();
}
@@ -115,7 +115,7 @@ that all have constraints on their properties.
{
// ...
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new Assert\Traverse());
}
diff --git a/reference/constraints/Type.rst b/reference/constraints/Type.rst
index 6f99fe76b3c..e1b41c7e350 100644
--- a/reference/constraints/Type.rst
+++ b/reference/constraints/Type.rst
@@ -33,19 +33,19 @@ This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\A
class Author
{
#[Assert\Type(Address::class)]
- protected $emailAddress;
+ protected Address $emailAddress;
#[Assert\Type('string')]
- protected $firstName;
+ protected string $firstName;
#[Assert\Type(
type: 'integer',
message: 'The value {{ value }} is not a valid {{ type }}.',
)]
- protected $age;
+ protected int $age;
#[Assert\Type(type: ['alpha', 'digit'])]
- protected $accessCode;
+ protected string $accessCode;
}
.. code-block:: yaml
@@ -115,7 +115,9 @@ This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\A
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('emailAddress', new Assert\Type(Address::class));
diff --git a/reference/constraints/Ulid.rst b/reference/constraints/Ulid.rst
index 1ecdbf6659f..59b481b3175 100644
--- a/reference/constraints/Ulid.rst
+++ b/reference/constraints/Ulid.rst
@@ -24,7 +24,7 @@ Basic Usage
class File
{
#[Assert\Ulid]
- protected $identifier;
+ protected string $identifier;
}
.. code-block:: yaml
@@ -60,6 +60,8 @@ Basic Usage
class File
{
+ // ...
+
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('identifier', new Assert\Ulid());
diff --git a/reference/constraints/Unique.rst b/reference/constraints/Unique.rst
index 4c5c5945e76..5c894bcc443 100644
--- a/reference/constraints/Unique.rst
+++ b/reference/constraints/Unique.rst
@@ -43,7 +43,7 @@ strings:
class Person
{
#[Assert\Unique]
- protected $contactEmails;
+ protected array $contactEmails;
}
.. code-block:: yaml
@@ -79,7 +79,9 @@ strings:
class Person
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('contactEmails', new Assert\Unique());
}
@@ -119,7 +121,7 @@ collection::
class Poi
{
#[Assert\Unique(fields=['latitude', 'longitude'])]
- protected $coordinates;
+ protected array $coordinates;
}
.. code-block:: yaml
@@ -161,7 +163,9 @@ collection::
class Poi
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('coordinates', new Assert\Unique([
'fields' => ['latitude', 'longitude'],
diff --git a/reference/constraints/UniqueEntity.rst b/reference/constraints/UniqueEntity.rst
index fc00b3b9476..8ad7ed1526a 100644
--- a/reference/constraints/UniqueEntity.rst
+++ b/reference/constraints/UniqueEntity.rst
@@ -48,7 +48,7 @@ between all of the rows in your user table:
{
#[ORM\Column(name: 'email', type: 'string', length: 255, unique: true)]
#[Assert\Email]
- protected $email;
+ protected string $email;
}
.. code-block:: yaml
@@ -91,7 +91,9 @@ between all of the rows in your user table:
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addConstraint(new UniqueEntity([
'fields' => 'email',
diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst
index 47b90a05c37..2c3420df7c6 100644
--- a/reference/constraints/Url.rst
+++ b/reference/constraints/Url.rst
@@ -24,7 +24,7 @@ Basic Usage
class Author
{
#[Assert\Url]
- protected $bioUrl;
+ protected string $bioUrl;
}
.. code-block:: yaml
@@ -60,7 +60,9 @@ Basic Usage
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url());
}
@@ -107,7 +109,7 @@ Parameter Description
#[Assert\Url(
message: 'The url {{ value }} is not a valid url',
)]
- protected $bioUrl;
+ protected string $bioUrl;
}
.. code-block:: yaml
@@ -146,7 +148,9 @@ Parameter Description
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url([
'message' => 'The url "{{ value }}" is not a valid url.',
@@ -181,7 +185,7 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing
#[Assert\Url(
protocols: ['http', 'https', 'ftp'],
)]
- protected $bioUrl;
+ protected string $bioUrl;
}
.. code-block:: yaml
@@ -223,7 +227,9 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url([
'protocols' => ['http', 'https', 'ftp'],
@@ -254,7 +260,7 @@ also relative URLs that contain no protocol (e.g. ``//example.com``).
#[Assert\Url(
relativeProtocol: true,
)]
- protected $bioUrl;
+ protected string $bioUrl;
}
.. code-block:: yaml
@@ -292,7 +298,9 @@ also relative URLs that contain no protocol (e.g. ``//example.com``).
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('bioUrl', new Assert\Url([
'relativeProtocol' => true,
diff --git a/reference/constraints/UserPassword.rst b/reference/constraints/UserPassword.rst
index ad2d0a3eda8..5981be99b66 100644
--- a/reference/constraints/UserPassword.rst
+++ b/reference/constraints/UserPassword.rst
@@ -43,7 +43,7 @@ the user's current password:
#[SecurityAssert\UserPassword(
message: 'Wrong value for your current password',
)]
- protected $oldPassword;
+ protected string $oldPassword;
}
.. code-block:: yaml
@@ -84,7 +84,9 @@ the user's current password:
class ChangePassword
{
- public static function loadValidatorData(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorData(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint(
'oldPassword',
diff --git a/reference/constraints/Uuid.rst b/reference/constraints/Uuid.rst
index 14f6a3916e3..c93a4800713 100644
--- a/reference/constraints/Uuid.rst
+++ b/reference/constraints/Uuid.rst
@@ -27,7 +27,7 @@ Basic Usage
class File
{
#[Assert\Uuid]
- protected $identifier;
+ protected string $identifier;
}
.. code-block:: yaml
@@ -63,7 +63,9 @@ Basic Usage
class File
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('identifier', new Assert\Uuid());
}
diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst
index 3c0e1937708..e629d169247 100644
--- a/reference/constraints/Valid.rst
+++ b/reference/constraints/Valid.rst
@@ -24,8 +24,9 @@ stores an ``Address`` instance in the ``$address`` property::
class Address
{
- protected $street;
- protected $zipCode;
+ protected string $street;
+
+ protected string $zipCode;
}
.. code-block:: php
@@ -35,9 +36,11 @@ stores an ``Address`` instance in the ``$address`` property::
class Author
{
- protected $firstName;
- protected $lastName;
- protected $address;
+ protected string $firstName;
+
+ protected string $lastName;
+
+ protected Address $address;
}
.. configuration-block::
@@ -52,11 +55,11 @@ stores an ``Address`` instance in the ``$address`` property::
class Address
{
#[Assert\NotBlank]
- protected $street;
+ protected string $street;
#[Assert\NotBlank]
#[Assert\Length(max: 5)]
- protected $zipCode;
+ protected string $zipCode;
}
// src/Entity/Author.php
@@ -68,12 +71,12 @@ stores an ``Address`` instance in the ``$address`` property::
{
#[Assert\NotBlank]
#[Assert\Length(min: 4)]
- protected $firstName;
+ protected string $firstName;
#[Assert\NotBlank]
- protected $lastName;
+ protected string $lastName;
- protected $address;
+ protected Address $address;
}
.. code-block:: yaml
@@ -140,7 +143,9 @@ stores an ``Address`` instance in the ``$address`` property::
class Address
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('street', new Assert\NotBlank());
$metadata->addPropertyConstraint('zipCode', new Assert\NotBlank());
@@ -156,7 +161,9 @@ stores an ``Address`` instance in the ``$address`` property::
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('firstName', new Assert\NotBlank());
$metadata->addPropertyConstraint('firstName', new Assert\Length(['min' => 4]));
@@ -180,7 +187,7 @@ an invalid address. To prevent that, add the ``Valid`` constraint to the
class Author
{
#[Assert\Valid]
- protected $address;
+ protected Address $address;
}
.. code-block:: yaml
@@ -216,7 +223,9 @@ an invalid address. To prevent that, add the ``Valid`` constraint to the
class Author
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('address', new Assert\Valid());
}
diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst
index d5d6f10dd86..a67bf15f141 100644
--- a/reference/dic_tags.rst
+++ b/reference/dic_tags.rst
@@ -118,7 +118,7 @@ services:
use App\Lock\PostgresqlLock;
use App\Lock\SqliteLock;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set('app.mysql_lock', MysqlLock::class);
@@ -180,7 +180,7 @@ the generic ``app.lock`` service can be defined as follows:
use App\Lock\PostgresqlLock;
use App\Lock\SqliteLock;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set('app.mysql_lock', MysqlLock::class);
@@ -1097,12 +1097,12 @@ required option: ``alias``, which defines the name of the extractor::
class FooExtractor implements ExtractorInterface
{
- protected $prefix;
+ protected string $prefix;
/**
* Extracts translation messages from a template directory to the catalog.
*/
- public function extract($directory, MessageCatalogue $catalog)
+ public function extract(string $directory, MessageCatalogue $catalog)
{
// ...
}
diff --git a/serializer.rst b/serializer.rst
index 8da6df57c40..0afb1742f82 100644
--- a/serializer.rst
+++ b/serializer.rst
@@ -176,7 +176,7 @@ You can also specify the context on a per-property basis::
/**
* @Context({ DateTimeNormalizer::FORMAT_KEY = 'Y-m-d' })
*/
- public $createdAt;
+ public \DateTimeInterface $createdAt;
// ...
}
@@ -191,7 +191,7 @@ You can also specify the context on a per-property basis::
class Person
{
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
- public $createdAt;
+ public \DateTimeInterface $createdAt;
// ...
}
@@ -234,7 +234,7 @@ Use the options to specify context specific to normalization or denormalization:
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339],
)]
- public $createdAt;
+ public \DateTimeInterface $createdAt;
// ...
}
@@ -255,7 +255,7 @@ You can also restrict the usage of a context to some groups::
context: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339_EXTENDED],
groups: ['extended'],
)]
- public $createdAt;
+ public \DateTimeInterface $createdAt;
// ...
}
diff --git a/service_container/alias_private.rst b/service_container/alias_private.rst
index 4956bcee957..33d26c8d0b7 100644
--- a/service_container/alias_private.rst
+++ b/service_container/alias_private.rst
@@ -55,7 +55,7 @@ You can also control the ``public`` option on a service-by-service basis:
use App\Service\Foo;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Foo::class)
@@ -127,7 +127,7 @@ services.
use App\Mail\PhpMailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(PhpMailer::class)
@@ -269,7 +269,7 @@ The following example shows how to inject an anonymous service into another serv
use App\AnonymousBar;
use App\Foo;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Foo::class)
@@ -320,7 +320,7 @@ Using an anonymous service as a factory looks like this:
use App\AnonymousBar;
use App\Foo;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Foo::class)
@@ -366,7 +366,7 @@ or you decided not to maintain it anymore), you can deprecate its definition:
use App\Service\OldService;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(OldService::class)
diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst
index d1fce9f20fd..4f62e24e10f 100644
--- a/service_container/autowiring.rst
+++ b/service_container/autowiring.rst
@@ -102,7 +102,7 @@ both services:
.. code-block:: php
// config/services.php
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services()
->defaults()
->autowire()
@@ -239,7 +239,7 @@ adding a service alias:
use App\Util\Rot13Transformer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
// ...
// the id is not a class, so it won't be used for autowiring
@@ -347,7 +347,7 @@ To fix that, add an :ref:`alias `:
use App\Util\Rot13Transformer;
use App\Util\TransformerInterface;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
// ...
$services->set(Rot13Transformer::class);
@@ -512,7 +512,7 @@ the injection::
use App\Util\TransformerInterface;
use App\Util\UppercaseTransformer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
// ...
$services->set(Rot13Transformer::class)->autowire();
diff --git a/service_container/calls.rst b/service_container/calls.rst
index 0ae5bb76e06..98f9dc2bc86 100644
--- a/service_container/calls.rst
+++ b/service_container/calls.rst
@@ -66,7 +66,7 @@ To configure the container to call the ``setLogger`` method, use the ``calls`` k
use App\Service\MessageGenerator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
// ...
$services->set(MessageGenerator::class)
diff --git a/service_container/configurators.rst b/service_container/configurators.rst
index 6505c496863..2cf9cdb471f 100644
--- a/service_container/configurators.rst
+++ b/service_container/configurators.rst
@@ -167,7 +167,7 @@ all the classes are already loaded as services. All you need to do is specify th
use App\Mail\GreetingCardManager;
use App\Mail\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// Registers all 4 classes as services, including App\Mail\EmailConfigurator
@@ -236,7 +236,7 @@ Services can be configured via invokable configurators (replacing the
use App\Mail\GreetingCardManager;
use App\Mail\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// Registers all 4 classes as services, including App\Mail\EmailConfigurator
diff --git a/service_container/expression_language.rst b/service_container/expression_language.rst
index e5a025276dc..7847a87b3b8 100644
--- a/service_container/expression_language.rst
+++ b/service_container/expression_language.rst
@@ -55,7 +55,7 @@ to another service: ``App\Mailer``. One way to do this is with an expression:
use App\Mail\MailerConfiguration;
use App\Mailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
// ...
$services->set(MailerConfiguration::class);
@@ -116,7 +116,7 @@ via a ``container`` variable. Here's another example:
use App\Mailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class)
diff --git a/service_container/factories.rst b/service_container/factories.rst
index 452b073ffe1..9e46faf9d88 100644
--- a/service_container/factories.rst
+++ b/service_container/factories.rst
@@ -74,7 +74,7 @@ create its object:
use App\Email\NewsletterManager;
use App\Email\NewsletterManagerStaticFactory;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
@@ -156,7 +156,7 @@ You can omit the class on the factory declaration:
use App\Email\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// Note that we are not using service()
@@ -218,7 +218,7 @@ Configuration of the service container then looks like this:
use App\Email\NewsletterManager;
use App\Email\NewsletterManagerFactory;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// first, create a service for the factory
@@ -296,7 +296,7 @@ method name:
use App\Email\NewsletterManager;
use App\Email\NewsletterManagerFactory;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
@@ -432,7 +432,7 @@ previous examples takes the ``templating`` service as an argument:
use App\Email\NewsletterManager;
use App\Email\NewsletterManagerFactory;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
diff --git a/service_container/import.rst b/service_container/import.rst
index 1e0fcfb2cee..d5056032115 100644
--- a/service_container/import.rst
+++ b/service_container/import.rst
@@ -116,7 +116,7 @@ a relative or absolute path to the imported file:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$container->import('services/mailer.php');
// If you want to import a whole directory:
$container->import('services/');
diff --git a/service_container/injection_types.rst b/service_container/injection_types.rst
index 959a0008207..060a95bffc0 100644
--- a/service_container/injection_types.rst
+++ b/service_container/injection_types.rst
@@ -69,7 +69,7 @@ service container configuration:
use App\Mail\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
@@ -272,7 +272,7 @@ that accepts the dependency::
use App\Mail\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
@@ -311,7 +311,7 @@ Another possibility is setting public fields of the class directly::
// ...
class NewsletterManager
{
- public $mailer;
+ public MailerInterface $mailer;
// ...
}
diff --git a/service_container/lazy_services.rst b/service_container/lazy_services.rst
index 3f1fa45f547..663118504cc 100644
--- a/service_container/lazy_services.rst
+++ b/service_container/lazy_services.rst
@@ -71,7 +71,7 @@ You can mark the service as ``lazy`` by manipulating its definition:
use App\Twig\AppExtension;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(AppExtension::class)->lazy();
@@ -152,7 +152,7 @@ specific interfaces.
use App\Twig\AppExtension;
use Twig\Extension\ExtensionInterface;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(AppExtension::class)
diff --git a/service_container/optional_dependencies.rst b/service_container/optional_dependencies.rst
index c555b7f05c8..bc8f03cf7e0 100644
--- a/service_container/optional_dependencies.rst
+++ b/service_container/optional_dependencies.rst
@@ -38,7 +38,7 @@ if the service does not exist:
use App\Newsletter\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
@@ -94,7 +94,7 @@ call if the service exists and remove the method call if it does not:
use App\Newsletter\NewsletterManager;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(NewsletterManager::class)
diff --git a/service_container/parent_services.rst b/service_container/parent_services.rst
index 1719176f34b..6fea615bc63 100644
--- a/service_container/parent_services.rst
+++ b/service_container/parent_services.rst
@@ -15,7 +15,7 @@ you may have multiple repository classes which need the
// ...
abstract class BaseDoctrineRepository
{
- protected $logger;
+ protected LoggerInterface $logger;
public function __construct(
protected ObjectManager $objectManager,
@@ -118,7 +118,7 @@ avoid duplicated service definitions:
use App\Repository\DoctrinePostRepository;
use App\Repository\DoctrineUserRepository;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(BaseDoctrineRepository::class)
@@ -227,7 +227,7 @@ the child class:
use App\Repository\DoctrineUserRepository;
// ...
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(BaseDoctrineRepository::class)
diff --git a/service_container/service_decoration.rst b/service_container/service_decoration.rst
index f32c0cc271c..b772fbd2ad3 100644
--- a/service_container/service_decoration.rst
+++ b/service_container/service_decoration.rst
@@ -41,7 +41,7 @@ When overriding an existing definition, the original service is lost:
use App\Mailer;
use App\NewMailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class);
@@ -112,7 +112,7 @@ but keeps a reference of the old one as ``.inner``:
use App\DecoratingMailer;
use App\Mailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class);
@@ -200,7 +200,7 @@ automatically changed to ``'.inner'``):
use App\DecoratingMailer;
use App\Mailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class);
@@ -266,7 +266,7 @@ automatically changed to ``'.inner'``):
use App\DecoratingMailer;
use App\Mailer;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Mailer::class);
@@ -355,7 +355,7 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(\Foo::class);
@@ -442,7 +442,7 @@ ordered services, each one decorating the next:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$container->services()
->stack('decorated_foo_stack', [
inline_service(\Baz::class)->args([service('.inner')]),
@@ -525,7 +525,7 @@ advanced example of composition:
use App\Decorated;
use App\Decorator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$container->services()
->set('some_decorator', Decorator::class)
@@ -657,7 +657,7 @@ Three different behaviors are available:
use Symfony\Component\DependencyInjection\ContainerInterface;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(Foo::class);
diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst
index 0844a74be43..babb7849fa8 100644
--- a/service_container/service_subscribers_locators.rst
+++ b/service_container/service_subscribers_locators.rst
@@ -232,7 +232,7 @@ service type to a service.
use App\CommandBus;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(CommandBus::class)
@@ -379,7 +379,7 @@ or directly via PHP attributes:
use App\CommandBus;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(CommandBus::class)
@@ -458,7 +458,7 @@ other services. To do so, create a new service definition using the
use Symfony\Component\DependencyInjection\ServiceLocator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set('app.command_handler_locator', ServiceLocator::class)
@@ -519,7 +519,7 @@ Now you can inject the service locator in any other services:
use App\CommandBus;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(CommandBus::class)
@@ -627,7 +627,7 @@ of the ``key`` tag attribute (as defined in the ``index_by`` locator option):
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(App\Handler\One::class)
@@ -734,7 +734,7 @@ attribute to the locator service defining the name of this custom method:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$container->services()
->set(App\HandlerCollection::class)
->args([tagged_locator('app.handler', 'key', 'myOwnMethodName')])
diff --git a/service_container/shared.rst b/service_container/shared.rst
index 435822fb25c..85db809a840 100644
--- a/service_container/shared.rst
+++ b/service_container/shared.rst
@@ -33,7 +33,7 @@ in your service definition:
use App\SomeNonSharedService;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(SomeNonSharedService::class)
diff --git a/service_container/synthetic_services.rst b/service_container/synthetic_services.rst
index fc26c6848d3..b2bc5e72f53 100644
--- a/service_container/synthetic_services.rst
+++ b/service_container/synthetic_services.rst
@@ -63,7 +63,7 @@ configuration:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// synthetic services don't specify a class
diff --git a/service_container/tags.rst b/service_container/tags.rst
index a2639729ff8..64c673d131c 100644
--- a/service_container/tags.rst
+++ b/service_container/tags.rst
@@ -37,7 +37,7 @@ example:
use App\Twig\AppExtension;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(AppExtension::class)
@@ -103,7 +103,7 @@ If you want to apply tags automatically for your own services, use the
use App\Security\CustomInterface;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
// this config only applies to the services created by this file
@@ -273,7 +273,7 @@ Then, define the chain as a service:
use App\Mail\TransportChain;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(TransportChain::class);
@@ -327,7 +327,7 @@ For example, you may add the following transports as services:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(\MailerSmtpTransport::class)
@@ -495,7 +495,7 @@ To answer this, change the service declaration:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(\MailerSmtpTransport::class)
@@ -654,7 +654,7 @@ directly via PHP attributes:
// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(App\Handler\One::class)
@@ -801,7 +801,7 @@ the number, the earlier the tagged service will be located in the collection:
use App\Handler\One;
- return function(ContainerConfigurator $container) {
+ return function(ContainerConfigurator $container): void {
$services = $container->services();
$services->set(One::class)
diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst
index 9ec87790d3e..105a6b5afdc 100644
--- a/validation/custom_constraint.rst
+++ b/validation/custom_constraint.rst
@@ -46,7 +46,7 @@ You can use ``#[HasNamedArguments]`` to make some constraint options required::
#[\Attribute]
class ContainsAlphanumeric extends Constraint
{
- public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
+ public string $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
#[HasNamedArguments]
public function __construct(
diff --git a/validation/severity.rst b/validation/severity.rst
index e45e04d089e..632a99519d9 100644
--- a/validation/severity.rst
+++ b/validation/severity.rst
@@ -31,13 +31,13 @@ Use the ``payload`` option to configure the error level for each constraint:
class User
{
#[Assert\NotBlank(payload: ['severity' => 'error'])]
- protected $username;
+ protected string $username;
#[Assert\NotBlank(payload: ['severity' => 'error'])]
- protected $password;
+ protected string $password;
#[Assert\Iban(payload: ['severity' => 'warning'])]
- protected $bankAccountNumber;
+ protected string $bankAccountNumber;
}
.. code-block:: yaml
@@ -101,7 +101,9 @@ Use the ``payload`` option to configure the error level for each constraint:
class User
{
- public static function loadValidatorMetadata(ClassMetadata $metadata)
+ // ...
+
+ public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('username', new Assert\NotBlank([
'payload' => ['severity' => 'error'],