Completed
Push — AdamKasp--refactor-and-upgrade... ( dfa618...fc27b6 )
by Kamil
05:14
created

CustomerRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A countCustomers() 0 8 1
A countCustomersInPeriod() 0 12 1
A findLatest() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
15
16
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
17
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
18
19
class CustomerRepository extends EntityRepository implements CustomerRepositoryInterface
20
{
21
    public function countCustomers(): int
22
    {
23
        return (int) $this->createQueryBuilder('o')
24
            ->select('COUNT(o.id)')
25
            ->getQuery()
26
            ->getSingleScalarResult()
27
        ;
28
    }
29
30
    public function countCustomersInPeriod(\DateTimeInterface $startDate, \DateTimeInterface $endDate): int
31
    {
32
        return (int) $this->createQueryBuilder('o')
33
            ->select('COUNT(o.id)')
34
            ->where('o.createdAt >= :startDate')
35
            ->andWhere('o.createdAt <= :endDate')
36
            ->setParameter('startDate', $startDate)
37
            ->setParameter('endDate', $endDate)
38
            ->getQuery()
39
            ->getSingleScalarResult()
40
        ;
41
    }
42
43
    public function findLatest(int $count): array
44
    {
45
        return $this->createQueryBuilder('o')
46
            ->addOrderBy('o.createdAt', 'DESC')
47
            ->setMaxResults($count)
48
            ->getQuery()
49
            ->getResult()
50
        ;
51
    }
52
}
53