diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index 5be66b8..3fea0c4 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -18,8 +18,14 @@ use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\UX\Turbo\TurboBundle; use Symfony\Component\HttpFoundation\JsonResponse; +/** + * CRUD on posts and comments. + */ class PostController extends AbstractController { + /** + * The number of item on a page for the pagination. + */ private const POSTS_PER_PAGE = 10; #[Route('/', name: 'app_posts')] @@ -36,7 +42,7 @@ class PostController extends AbstractController } #[Route('/posts', name: 'app_post_index', methods: ['GET'])] - public function table(PostRepository $repository): Response + public function table(): Response { return $this->redirectToRoute('app_posts', [], Response::HTTP_SEE_OTHER); } diff --git a/src/DataFixtures/AppFixtures.php b/src/DataFixtures/AppFixtures.php index 6bff9e2..dbac25c 100644 --- a/src/DataFixtures/AppFixtures.php +++ b/src/DataFixtures/AppFixtures.php @@ -10,6 +10,9 @@ use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; +/** + * Creates fake data for testing purposes. + */ class AppFixtures extends Fixture { public function __construct( @@ -20,10 +23,12 @@ class AppFixtures extends Fixture public function load(ObjectManager $manager): void { + // Dummy user $user = (new User())->setEmail('test@test.fr'); $user->setPassword($this->passwordHasher->hashPassword($user, 'password')); $manager->persist($user); + // Posts and their species $faker = \Faker\Factory::create(); for ($i = 0; $i < 20; ++$i) { $name = $faker->name(); diff --git a/src/EventListener/LocaleListener.php b/src/EventListener/LocaleListener.php index 6a56c8c..4d3b636 100644 --- a/src/EventListener/LocaleListener.php +++ b/src/EventListener/LocaleListener.php @@ -7,6 +7,9 @@ use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Translation\LocaleSwitcher; +/** + * Reads the locale from the user session and change it for every request. + */ final readonly class LocaleListener { public function __construct(private LocaleSwitcher $localeSwitcher) diff --git a/src/Security/Voter/CommentVoter.php b/src/Security/Voter/CommentVoter.php index 8761145..34b1686 100644 --- a/src/Security/Voter/CommentVoter.php +++ b/src/Security/Voter/CommentVoter.php @@ -6,6 +6,9 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\User\UserInterface; +/** + * Only allow admins or comment owners to edit their comments. + */ class CommentVoter extends Voter { public const EDIT = 'COMMENT_EDIT'; diff --git a/src/Service/ImageSafetyServiceInterface.php b/src/Service/ImageSafetyServiceInterface.php index 5c722b1..8922056 100644 --- a/src/Service/ImageSafetyServiceInterface.php +++ b/src/Service/ImageSafetyServiceInterface.php @@ -4,6 +4,9 @@ namespace App\Service; use Symfony\Component\HttpFoundation\File\File; +/** + * Ensures that an image is safe. + */ interface ImageSafetyServiceInterface { public function isValid(File $file): bool; diff --git a/src/State/UserPasswordHasher.php b/src/State/UserPasswordHasher.php index 0fc91be..c1b2450 100644 --- a/src/State/UserPasswordHasher.php +++ b/src/State/UserPasswordHasher.php @@ -8,6 +8,8 @@ use App\Entity\User; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; /** + * Hashes plain text password in the API. + * * @implements ProcessorInterface */ final readonly class UserPasswordHasher implements ProcessorInterface diff --git a/templates/comment/comment.html.twig b/templates/comment/comment.html.twig index 14458c2..1b65c54 100644 --- a/templates/comment/comment.html.twig +++ b/templates/comment/comment.html.twig @@ -2,9 +2,9 @@
- {{ comment.author.email }} le {{ comment.createdAt | date }} + {{ 'commented_at'|trans({ email: comment.author.email, date: comment.createdAt|date }) }} {% if comment.createdAt != comment.editedAt %} - (modifié le {{ comment.editedAt | date }}) + {{ 'edited_at'|trans({ date: comment.editedAt|date }) }} {% endif %}

{{ comment.content }}

diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 587e1f6..488265e 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -161,6 +161,14 @@ save Save + + commented_at + email on date + + + edited_at + edited on date + diff --git a/translations/messages.fr.xlf b/translations/messages.fr.xlf index 72ebfe4..d716bfc 100644 --- a/translations/messages.fr.xlf +++ b/translations/messages.fr.xlf @@ -161,6 +161,14 @@ save Sauvegarder + + commented_at + email le date + + + edited_at + édité le date +