Completed
Pull Request — master (#200)
by Loïc
02:31
created

CustomerRepository::findLatest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
29
    public function findLatest(int $count): array
30
    {
31
        return $this->createQueryBuilder('o')
32
            ->addSelect('user')
33
            ->leftJoin('o.user', 'user')
34
            ->addOrderBy('o.createdAt', 'DESC')
35
            ->setMaxResults($count)
36
            ->getQuery()
37
            ->getResult();
38
    }
39
}
40