Skip to content

Commit 1cb130d

Browse files
authored
Use PHP8 typed properties
Use property type
1 parent 72f0db4 commit 1cb130d

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

core/dto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use Symfony\Component\Validator\Constraints as Assert;
2020
final class UserResetPasswordDto
2121
{
2222
#[Assert\Email]
23-
public $email;
23+
public string $email;
2424
}
2525
```
2626

core/events.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,8 @@ use Symfony\Component\Mailer\MailerInterface;
103103

104104
final class BookMailSubscriber implements EventSubscriberInterface
105105
{
106-
private $mailer;
107-
108-
public function __construct(MailerInterface $mailer)
106+
public function __construct(private MailerInterface $mailer)
109107
{
110-
$this->mailer = $mailer;
111108
}
112109

113110
public static function getSubscribedEvents()

core/identifiers.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ use App\Uuid;
2424
#[ApiResource(provider: PersonProvider::class)]
2525
final class Person
2626
{
27-
/**
28-
* @var Uuid
29-
*/
3027
#[ApiProperty(identifier: true)]
31-
public $code;
28+
public Uuid $code;
3229

3330
// ...
3431
}
@@ -214,12 +211,9 @@ final class Person
214211
#[ApiProperty(identifier: false)]
215212
private ?int $id = null;
216213

217-
/**
218-
* @var Uuid
219-
*/
220214
#[ORM\Column(type: 'uuid', unique: true)]
221215
#[ApiProperty(identifier: true)]
222-
public $code;
216+
public Uuid $code;
223217

224218
// ...
225219
}

core/serialization.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,10 @@ use Symfony\Component\Serializer\Annotation\Groups;
548548
class Person
549549
{
550550
#[Groups('person')]
551-
public $name;
551+
public string $name;
552552
553-
/**
554-
* @var Person
555-
*/
556553
#[Groups('person')]
557-
public $parent; // Note that a Person instance has a relation with another Person.
554+
public ?Person $parent; // Note that a Person instance has a relation with another Person.
558555
559556
// ...
560557
}
@@ -607,7 +604,7 @@ class Person
607604
608605
#[Groups('person')]
609606
#[ApiProperty(readableLink: false, writableLink: false)]
610-
public Person $parent; // This property is now serialized/deserialized as an IRI.
607+
public ?Person $parent; // This property is now serialized/deserialized as an IRI.
611608
612609
// ...
613610
}
@@ -808,9 +805,8 @@ class Greeting
808805
#[Groups("greeting:collection:get")]
809806
private ?int $id = null;
810807
811-
private $a = 1;
812-
813-
private $b = 2;
808+
private int $a = 1;
809+
private int $b = 2;
814810
815811
#[ORM\Column]
816812
#[Groups("greeting:collection:get")]
@@ -1182,7 +1178,7 @@ class Book
11821178
// ...
11831179
11841180
#[ApiProperty(identifier: true)]
1185-
private $id;
1181+
private ?int $id;
11861182
11871183
/**
11881184
* This field can be managed only by an admin

0 commit comments

Comments
 (0)