Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AlbumController
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
5 / 5
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 add
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 update
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 delete
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Controller\Admin;
4
5use App\Entity\Album;
6use App\Form\AlbumType;
7use App\Repository\AlbumRepository;
8use Doctrine\ORM\EntityManagerInterface;
9use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10use Symfony\Component\HttpFoundation\Request;
11use Symfony\Component\HttpFoundation\Response;
12use Symfony\Component\Routing\Attribute\Route;
13
14#[Route("/admin/album")]
15class AlbumController extends AbstractController
16{
17    public function __construct(
18        private AlbumRepository $albumRepository,
19        private EntityManagerInterface $entityManager,
20    ) {}
21
22    #[Route("", name: "admin_album_index")]
23    public function index(): Response
24    {
25        $albums = $this->albumRepository->findAll();
26
27        return $this->render('admin/album/index.html.twig', ['albums' => $albums]);
28    }
29
30    #[Route("/add", name: "admin_album_add")]
31    public function add(Request $request): Response
32    {
33        $album = new Album();
34        $form = $this->createForm(AlbumType::class, $album);
35        $form->handleRequest($request);
36
37        if ($form->isSubmitted() && $form->isValid()) {
38            $this->entityManager->persist($album);
39            $this->entityManager->flush();
40
41            return $this->redirectToRoute('admin_album_index');
42        }
43
44        return $this->render('admin/album/add.html.twig', ['form' => $form->createView()]);
45    }
46
47    #[Route("/update/{id}", name: "admin_album_update")]
48    public function update(Request $request, int $id): Response
49    {
50        $album = $this->albumRepository->find($id);
51        $form = $this->createForm(AlbumType::class, $album);
52        $form->handleRequest($request);
53
54        if ($form->isSubmitted() && $form->isValid()) {
55            $this->entityManager->flush();
56
57            return $this->redirectToRoute('admin_album_index');
58        }
59
60        return $this->render('admin/album/update.html.twig', ['form' => $form->createView()]);
61    }
62
63    #[Route("/delete/{id}", name: "admin_album_delete")]
64    public function delete(int $id): Response
65    {
66        $album = $this->albumRepository->find($id);
67        $this->entityManager->remove($album);
68        $this->entityManager->flush();
69
70        return $this->redirectToRoute('admin_album_index');
71    }
72}