From 1cb130daba239fb0557558c785793fd8f9c951ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 12 Feb 2025 09:17:07 +0100 Subject: [PATCH] Use PHP8 typed properties Use property type --- core/dto.md | 2 +- core/events.md | 5 +---- core/identifiers.md | 10 ++-------- core/serialization.md | 16 ++++++---------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/core/dto.md b/core/dto.md index b3c353b7870..ca47d83cc14 100644 --- a/core/dto.md +++ b/core/dto.md @@ -20,7 +20,7 @@ use Symfony\Component\Validator\Constraints as Assert; final class UserResetPasswordDto { #[Assert\Email] - public $email; + public string $email; } ``` diff --git a/core/events.md b/core/events.md index 4b17dfab79d..6ceee75229c 100644 --- a/core/events.md +++ b/core/events.md @@ -103,11 +103,8 @@ use Symfony\Component\Mailer\MailerInterface; final class BookMailSubscriber implements EventSubscriberInterface { - private $mailer; - - public function __construct(MailerInterface $mailer) + public function __construct(private MailerInterface $mailer) { - $this->mailer = $mailer; } public static function getSubscribedEvents() diff --git a/core/identifiers.md b/core/identifiers.md index 8e8e9a31f27..65777a6db55 100644 --- a/core/identifiers.md +++ b/core/identifiers.md @@ -24,11 +24,8 @@ use App\Uuid; #[ApiResource(provider: PersonProvider::class)] final class Person { - /** - * @var Uuid - */ #[ApiProperty(identifier: true)] - public $code; + public Uuid $code; // ... } @@ -214,12 +211,9 @@ final class Person #[ApiProperty(identifier: false)] private ?int $id = null; - /** - * @var Uuid - */ #[ORM\Column(type: 'uuid', unique: true)] #[ApiProperty(identifier: true)] - public $code; + public Uuid $code; // ... } diff --git a/core/serialization.md b/core/serialization.md index 9527f248e8a..4c0fd4a37fa 100644 --- a/core/serialization.md +++ b/core/serialization.md @@ -548,13 +548,10 @@ use Symfony\Component\Serializer\Annotation\Groups; class Person { #[Groups('person')] - public $name; + public string $name; - /** - * @var Person - */ #[Groups('person')] - public $parent; // Note that a Person instance has a relation with another Person. + public ?Person $parent; // Note that a Person instance has a relation with another Person. // ... } @@ -607,7 +604,7 @@ class Person #[Groups('person')] #[ApiProperty(readableLink: false, writableLink: false)] - public Person $parent; // This property is now serialized/deserialized as an IRI. + public ?Person $parent; // This property is now serialized/deserialized as an IRI. // ... } @@ -808,9 +805,8 @@ class Greeting #[Groups("greeting:collection:get")] private ?int $id = null; - private $a = 1; - - private $b = 2; + private int $a = 1; + private int $b = 2; #[ORM\Column] #[Groups("greeting:collection:get")] @@ -1182,7 +1178,7 @@ class Book // ... #[ApiProperty(identifier: true)] - private $id; + private ?int $id; /** * This field can be managed only by an admin