Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Index
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
2
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
 __invoke
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Controller\Transactions;
6
7use App\Controller\BaseController;
8use App\Helper\Paginator\PaginatorTrait;
9use App\Repository\StoreRepository;
10use App\Repository\TransactionRepository;
11use App\Type\TransactionType;
12use Symfony\Component\DependencyInjection\Attribute\Autowire;
13use Symfony\Component\HttpFoundation\Request;
14use Symfony\Component\HttpFoundation\Response;
15use Symfony\Component\Routing\Attribute\Route;
16use Symfony\Component\Security\Http\Attribute\IsGranted;
17
18#[IsGranted('ROLE_ADMIN')]
19#[Route(path: '/transactions', name: 'transactions_index', methods: ['GET', 'POST'])]
20class 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}