Completed
Push — master ( 87f06d...e62357 )
by Loïc
02:09 queued 10s
created

CustomerRepository::countCustomers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of monofony.
5
 *
6
 * (c) Mobizel
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 App\Repository;
15
16
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
17
18
class CustomerRepository extends EntityRepository
19
{
20
    public function countCustomers(): int
21
    {
22
        return (int) $this->createQueryBuilder('o')
23
            ->select('COUNT(o.id)')
24
            ->getQuery()
25
            ->getSingleScalarResult();
26
    }
27
28
    public function findLatest(int $count): array
29
    {
30
        return $this->createQueryBuilder('o')
31
            ->addSelect('user')
32
            ->leftJoin('o.user', 'user')
33
            ->addOrderBy('o.createdAt', 'DESC')
34
            ->setMaxResults($count)
35
            ->getQuery()
36
            ->getResult();
37
    }
38
}
39