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

CustomerRepository::findLatest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 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