Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Index | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\Transactions; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Helper\Paginator\PaginatorTrait; |
| 9 | use App\Repository\StoreRepository; |
| 10 | use App\Repository\TransactionRepository; |
| 11 | use App\Type\TransactionType; |
| 12 | use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 13 | use Symfony\Component\HttpFoundation\Request; |
| 14 | use Symfony\Component\HttpFoundation\Response; |
| 15 | use Symfony\Component\Routing\Attribute\Route; |
| 16 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 17 | |
| 18 | #[IsGranted('ROLE_ADMIN')] |
| 19 | #[Route(path: '/transactions', name: 'transactions_index', methods: ['GET', 'POST'])] |
| 20 | class Index extends BaseController |
| 21 | { |
| 22 | use PaginatorTrait; |
| 23 | |
| 24 | public function __construct(private readonly StoreRepository $storeRepo, private readonly TransactionRepository $transactionRepo) {} |
| 25 | |
| 26 | public function __invoke( |
| 27 | Request $request, |
| 28 | #[Autowire('%env(LIST_LIMIT)%')] |
| 29 | int $listLimit, |
| 30 | ): Response |
| 31 | { |
| 32 | $paginatorOptions = $this->getPaginatorOptions($request, $listLimit); |
| 33 | $transactions = $this->transactionRepo->getRawList($paginatorOptions); |
| 34 | $paginatorOptions->setMaxPages( |
| 35 | (int)ceil( |
| 36 | $transactions->count() / $paginatorOptions->getLimit() |
| 37 | ) |
| 38 | ); |
| 39 | |
| 40 | return $this->render( |
| 41 | 'transaction/index.html.twig', |
| 42 | [ |
| 43 | 'transactions' => $transactions, |
| 44 | 'paginatorOptions' => $paginatorOptions, |
| 45 | 'transactionTypes' => TransactionType::cases(), |
| 46 | 'stores' => $this->storeRepo->findAll(), |
| 47 | ] |
| 48 | ); |
| 49 | } |
| 50 | } |