Passed
Push — master ( d1b72a...68b5a8 )
by Anatoly
01:04 queued 11s
created

EntryRepository::countAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace App\Bundle\Example\Repository;
4
5
/**
6
 * Import classes
7
 */
8
use App\Bundle\Example\Entity\Entry;
9
use Doctrine\ORM\EntityRepository;
10
11
/**
12
 * EntryRepository
13
 */
14
final class EntryRepository extends EntityRepository
15
{
16
17
    /**
18
     * Counts all entries
19
     *
20
     * @return int
21
     */
22 12
    public function countAll() : int
23
    {
24 12
        $qb = $this->getEntityManager()
25 12
            ->createQueryBuilder();
26
27 12
        $qb->select('count(entry.id)')
28 12
            ->from(Entry::class, 'entry');
29
30 12
        return (int) $qb->getQuery()
31 12
            ->getSingleScalarResult();
32
    }
33
34
    /**
35
     * Gets the list of entries
36
     *
37
     * @param null|int $limit
38
     * @param null|int $offset
39
     *
40
     * @return Entry[]
41
     */
42 1
    public function getList(?int $limit, ?int $offset) : array
43
    {
44 1
        $qb = $this->getEntityManager()
45 1
            ->createQueryBuilder();
46
47 1
        $qb->select('entry')
48 1
            ->from(Entry::class, 'entry')
49 1
            ->orderBy('entry.createdAt', 'DESC');
50
51 1
        return $qb->getQuery()
52 1
            ->setMaxResults($limit)
53 1
            ->setFirstResult($offset)
54 1
            ->getResult();
55
    }
56
}
57