Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ContractRepository | |
100.00% |
16 / 16 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findContracts | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |||
| findTemplate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Repository; |
| 6 | |
| 7 | use App\Entity\Contract; |
| 8 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
| 9 | use Doctrine\Persistence\ManagerRegistry; |
| 10 | |
| 11 | /** |
| 12 | * @method Contract|null find($id, $lockMode = null, $lockVersion = null) |
| 13 | * @method Contract|null findOneBy(array<string, mixed> $criteria, ?array<string, string> $orderBy = null) |
| 14 | * @method Contract[] findAll() |
| 15 | * @method Contract[] findBy(array<string, mixed> $criteria, ?array<string, string> $orderBy = null, $limit = null, $offset = null) |
| 16 | * |
| 17 | * @extends ServiceEntityRepository<Contract> |
| 18 | */ |
| 19 | class ContractRepository extends ServiceEntityRepository |
| 20 | { |
| 21 | public function __construct(ManagerRegistry $registry) |
| 22 | { |
| 23 | parent::__construct($registry, Contract::class); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return Contract[] |
| 28 | */ |
| 29 | public function findContracts(int $storeId = 0, int $year = 0): array |
| 30 | { |
| 31 | $query = $this->createQueryBuilder('c'); |
| 32 | |
| 33 | $query->where('c.id > 1'); |
| 34 | |
| 35 | if ($storeId !== 0) { |
| 36 | $query->andWhere('c.storeNumber = :storeId') |
| 37 | ->setParameter('storeId', $storeId); |
| 38 | } |
| 39 | |
| 40 | if ($year !== 0) { |
| 41 | $query->andWhere('YEAR(c.date) = :year') |
| 42 | ->setParameter('year', $year); |
| 43 | } |
| 44 | |
| 45 | $query->addOrderBy('c.date', 'DESC'); |
| 46 | $query->addOrderBy('c.storeNumber', 'ASC'); |
| 47 | |
| 48 | /** @var Contract[] $result */ |
| 49 | $result = $query |
| 50 | ->getQuery() |
| 51 | ->getResult(); |
| 52 | |
| 53 | return $result; |
| 54 | } |
| 55 | |
| 56 | public function findTemplate(): ?Contract |
| 57 | { |
| 58 | return $this->find(1); |
| 59 | } |
| 60 | } |