Passed
Push — master ( 77ad8d...3e3483 )
by Joachim
04:08
created

ReportRepository::findByUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStockMovementPlugin\Doctrine\ORM;
6
7
use Doctrine\ORM\NonUniqueResultException;
8
use Setono\SyliusStockMovementPlugin\Model\ReportConfigurationInterface;
9
use Setono\SyliusStockMovementPlugin\Model\ReportInterface;
10
use Setono\SyliusStockMovementPlugin\Repository\ReportRepositoryInterface;
11
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
12
13
final class ReportRepository extends EntityRepository implements ReportRepositoryInterface
14
{
15
    /**
16
     * @throws NonUniqueResultException
17
     */
18
    public function getLatestStockMovementIdOnAReport(ReportConfigurationInterface $reportConfiguration = null): int
19
    {
20
        $qb = $this->createQueryBuilder('r');
21
        $qb->select('MAX(s.id)')
22
            ->join('r.stockMovements', 's')
23
        ;
24
25
        if (null !== $reportConfiguration) {
26
            $qb->andWhere('r.reportConfiguration = :reportConfiguration')
27
                ->setParameter('reportConfiguration', $reportConfiguration)
28
            ;
29
        }
30
31
        return (int) $qb->getQuery()->getSingleScalarResult();
32
    }
33
34
    public function findByUuid(string $uuid): ?ReportInterface
35
    {
36
        /** @var ReportInterface|null $report */
37
        $report = $this->findOneBy([
38
            'uuid' => $uuid,
39
        ]);
40
41
        return $report;
42
    }
43
}
44