Skip to content

Commit b011284

Browse files
committed
Migrate constraints to attributes/named arguments.
1 parent 7816854 commit b011284

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

src/Entity/Comment.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ class Comment
5151
* @var string
5252
*
5353
* @ORM\Column(type="text")
54-
* @Assert\NotBlank(message="comment.blank")
55-
* @Assert\Length(
56-
* min=5,
57-
* minMessage="comment.too_short",
58-
* max=10000,
59-
* maxMessage="comment.too_long"
60-
* )
6154
*/
55+
#[
56+
Assert\NotBlank(message: 'comment.blank'),
57+
Assert\Length(
58+
min: 5,
59+
minMessage: 'comment.too_short',
60+
max: 10000,
61+
maxMessage: 'comment.too_long',
62+
)
63+
]
6264
private $content;
6365

6466
/**
@@ -81,9 +83,7 @@ public function __construct()
8183
$this->publishedAt = new \DateTime();
8284
}
8385

84-
/**
85-
* @Assert\IsTrue(message="comment.is_spam")
86-
*/
86+
#[Assert\IsTrue(message: 'comment.is_spam')]
8787
public function isLegitComment(): bool
8888
{
8989
$containsInvalidCharacters = null !== u($this->content)->indexOf('@');

src/Entity/Post.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class Post
4848
* @var string
4949
*
5050
* @ORM\Column(type="string")
51-
* @Assert\NotBlank
5251
*/
52+
#[Assert\NotBlank]
5353
private $title;
5454

5555
/**
@@ -63,18 +63,22 @@ class Post
6363
* @var string
6464
*
6565
* @ORM\Column(type="string")
66-
* @Assert\NotBlank(message="post.blank_summary")
67-
* @Assert\Length(max=255)
6866
*/
67+
#[
68+
Assert\NotBlank(message: 'post.blank_summary'),
69+
Assert\Length(max: 255),
70+
]
6971
private $summary;
7072

7173
/**
7274
* @var string
7375
*
7476
* @ORM\Column(type="text")
75-
* @Assert\NotBlank(message="post.blank_content")
76-
* @Assert\Length(min=10, minMessage="post.too_short_content")
7777
*/
78+
#[
79+
Assert\NotBlank(message: 'post.blank_content'),
80+
Assert\Length(min: 10, minMessage: 'post.too_short_content')
81+
]
7882
private $content;
7983

8084
/**
@@ -111,8 +115,8 @@ class Post
111115
* @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"})
112116
* @ORM\JoinTable(name="symfony_demo_post_tag")
113117
* @ORM\OrderBy({"name": "ASC"})
114-
* @Assert\Count(max="4", maxMessage="post.too_many_tags")
115118
*/
119+
#[Assert\Count(max: 4, maxMessage: 'post.too_many_tags')]
116120
private $tags;
117121

118122
public function __construct()

src/Entity/User.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,27 @@ class User implements UserInterface, \Serializable
4343
* @var string
4444
*
4545
* @ORM\Column(type="string")
46-
* @Assert\NotBlank()
4746
*/
47+
#[Assert\NotBlank]
4848
private $fullName;
4949

5050
/**
5151
* @var string
5252
*
5353
* @ORM\Column(type="string", unique=true)
54-
* @Assert\NotBlank()
55-
* @Assert\Length(min=2, max=50)
5654
*/
55+
#[
56+
Assert\NotBlank,
57+
Assert\Length(min: 2, max: 50)
58+
]
5759
private $username;
5860

5961
/**
6062
* @var string
6163
*
6264
* @ORM\Column(type="string", unique=true)
63-
* @Assert\Email()
6465
*/
66+
#[Assert\Email]
6567
private $email;
6668

6769
/**

src/Form/Type/ChangePasswordType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4545
'type' => PasswordType::class,
4646
'constraints' => [
4747
new NotBlank(),
48-
new Length([
49-
'min' => 5,
50-
'max' => 128,
51-
]),
48+
new Length(
49+
min: 5,
50+
max: 128,
51+
),
5252
],
5353
'first_options' => [
5454
'label' => 'label.new_password',

0 commit comments

Comments
 (0)