Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Create | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\Stores; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Entity\Store; |
| 9 | use App\Form\StoreType; |
| 10 | use App\Service\TaxService; |
| 11 | use Doctrine\ORM\EntityManagerInterface; |
| 12 | use Symfony\Component\HttpFoundation\Request; |
| 13 | use Symfony\Component\HttpFoundation\Response; |
| 14 | use Symfony\Component\Routing\Attribute\Route; |
| 15 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 16 | |
| 17 | #[IsGranted('ROLE_ADMIN')] |
| 18 | #[Route(path: 'stores/create', name: 'stores_create', methods: ['GET', 'POST'])] |
| 19 | class Create extends BaseController |
| 20 | { |
| 21 | public function __construct(private readonly TaxService $taxService) {} |
| 22 | |
| 23 | public function __invoke( |
| 24 | Request $request, |
| 25 | EntityManagerInterface $entityManager, |
| 26 | ): Response |
| 27 | { |
| 28 | $store = new Store(); |
| 29 | $form = $this->createForm(StoreType::class, $store); |
| 30 | $form->handleRequest($request); |
| 31 | if ($form->isSubmitted() && $form->isValid()) { |
| 32 | $entityManager->persist($store); |
| 33 | $entityManager->flush(); |
| 34 | |
| 35 | $this->addFlash('success', 'Store has been saved'); |
| 36 | |
| 37 | return $this->redirectToRoute('stores_index'); |
| 38 | } |
| 39 | |
| 40 | return $this->render( |
| 41 | 'stores/form.html.twig', |
| 42 | [ |
| 43 | 'form' => $form, |
| 44 | 'store' => $store, |
| 45 | 'ivaMultiplier' => $this->taxService->getTaxValue(), |
| 46 | ] |
| 47 | ); |
| 48 | } |
| 49 | } |