Passed
Push — master ( b6bdd2...5c5a86 )
by Joachim
11:55
created

OrderRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findOneByExternalId() 0 6 1
A findByInterval() 0 11 1
1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Repository;
4
5
use Loevgaard\DandomainFoundation\Entity\Generated\OrderInterface;
6
use Loevgaard\DandomainFoundation\Entity\Order;
7
use Loevgaard\DandomainFoundation\Repository\Generated\OrderRepositoryTrait;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
10
/**
11
 * @method null|OrderInterface find($id)
12
 * @method OrderInterface[]    findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null)
13
 * @method null|OrderInterface findOneBy(array $criteria)
14
 * @method OrderInterface[]    findAll()
15
 */
16
class OrderRepository extends AbstractRepository
17
{
18
    use OrderRepositoryTrait;
19
20
    public function __construct(RegistryInterface $registry)
21
    {
22
        parent::__construct($registry, Order::class);
23
    }
24
25
    public function findOneByExternalId(int $externalId): ?OrderInterface
26
    {
27
        /** @var OrderInterface $obj */
28
        $obj = $this->_findOneByExternalId($externalId);
29
30
        return $obj;
31
    }
32
33
    /**
34
     * @param \DateTimeInterface $start
35
     * @param \DateTimeInterface $end
36
     * @return OrderInterface[]
37
     */
38
    public function findByInterval(\DateTimeInterface $start, \DateTimeInterface $end)
39
    {
40
        $qb = $this->createQueryBuilder('o');
41
        $qb->where($qb->expr()->between('o.createdAt', ':start', ':end'))
42
            ->setParameters([
43
                'start' => $start,
44
                'end' => $end
45
            ])
46
        ;
47
48
        return $qb->getQuery()->getResult();
49
    }
50
}
51