Skip to content

Commit 8f84337

Browse files
committed
minor #1335 Don't use the syntax to group attributes (javiereguiluz)
This PR was squashed before being merged into the main branch. Discussion ---------- Don't use the syntax to group attributes The syntax proposed in this PR is the only one I see in Symfony applications. That's why I'm proposing this change. Do you agree on this change? Commits ------- 026b5d6 Don't use the syntax to group attributes
2 parents 9837e4d + 026b5d6 commit 8f84337

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

src/Controller/Admin/BlogController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
* @author Ryan Weaver <[email protected]>
3535
* @author Javier Eguiluz <[email protected]>
3636
*/
37-
#[Route('/admin/post'), IsGranted('ROLE_ADMIN')]
37+
#[Route('/admin/post')]
38+
#[IsGranted('ROLE_ADMIN')]
3839
class BlogController extends AbstractController
3940
{
4041
/**
@@ -48,10 +49,8 @@ class BlogController extends AbstractController
4849
* could move this annotation to any other controller while maintaining
4950
* the route name and therefore, without breaking any existing link.
5051
*/
51-
#[
52-
Route('/', methods: ['GET'], name: 'admin_index'),
53-
Route('/', methods: ['GET'], name: 'admin_post_index'),
54-
]
52+
#[Route('/', methods: ['GET'], name: 'admin_index')]
53+
#[Route('/', methods: ['GET'], name: 'admin_post_index')]
5554
public function index(PostRepository $posts): Response
5655
{
5756
$authorPosts = $posts->findBy(['author' => $this->getUser()], ['publishedAt' => 'DESC']);

src/Controller/BlogController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ class BlogController extends AbstractController
4242
*
4343
* See https://symfony.com/doc/current/routing.html#special-parameters
4444
*/
45-
#[
46-
Route('/', defaults: ['page' => '1', '_format' => 'html'], methods: ['GET'], name: 'blog_index'),
47-
Route('/rss.xml', defaults: ['page' => '1', '_format' => 'xml'], methods: ['GET'], name: 'blog_rss'),
48-
Route('/page/{page<[1-9]\d*>}', defaults: ['_format' => 'html'], methods: ['GET'], name: 'blog_index_paginated'),
49-
]
45+
#[Route('/', defaults: ['page' => '1', '_format' => 'html'], methods: ['GET'], name: 'blog_index')]
46+
#[Route('/rss.xml', defaults: ['page' => '1', '_format' => 'xml'], methods: ['GET'], name: 'blog_rss')]
47+
#[Route('/page/{page<[1-9]\d*>}', defaults: ['_format' => 'html'], methods: ['GET'], name: 'blog_index_paginated')]
5048
#[Cache(smaxage: 10)]
5149
public function index(Request $request, int $page, string $_format, PostRepository $posts, TagRepository $tags): Response
5250
{

src/Entity/Comment.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,8 @@ class Comment
3939
private ?Post $post = null;
4040

4141
#[ORM\Column(type: 'text')]
42-
#[
43-
Assert\NotBlank(message: 'comment.blank'),
44-
Assert\Length(
45-
min: 5,
46-
minMessage: 'comment.too_short',
47-
max: 10000,
48-
maxMessage: 'comment.too_long',
49-
)
50-
]
42+
#[Assert\NotBlank(message: 'comment.blank')]
43+
#[Assert\Length(min: 5, minMessage: 'comment.too_short', max: 10000, maxMessage: 'comment.too_long')]
5144
private ?string $content = null;
5245

5346
#[ORM\Column(type: 'datetime')]

src/Entity/Post.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ class Post
4848
private ?string $slug = null;
4949

5050
#[ORM\Column(type: 'string')]
51-
#[
52-
Assert\NotBlank(message: 'post.blank_summary'),
53-
Assert\Length(max: 255)
54-
]
51+
#[Assert\NotBlank(message: 'post.blank_summary')]
52+
#[Assert\Length(max: 255)]
5553
private ?string $summary = null;
5654

5755
#[ORM\Column(type: 'text')]
58-
#[
59-
Assert\NotBlank(message: 'post.blank_content'),
60-
Assert\Length(min: 10, minMessage: 'post.too_short_content')
61-
]
56+
#[Assert\NotBlank(message: 'post.blank_content')]
57+
#[Assert\Length(min: 10, minMessage: 'post.too_short_content')]
6258
private ?string $content = null;
6359

6460
#[ORM\Column(type: 'datetime')]

src/Entity/User.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
4141
private ?string $fullName = null;
4242

4343
#[ORM\Column(type: 'string', unique: true)]
44-
#[
45-
Assert\NotBlank,
46-
Assert\Length(min: 2, max: 50)
47-
]
44+
#[Assert\NotBlank]
45+
#[Assert\Length(min: 2, max: 50)]
4846
private ?string $username = null;
4947

5048
#[ORM\Column(type: 'string', unique: true)]

0 commit comments

Comments
 (0)