Passed
Pull Request — master (#10)
by Anatoly
02:28
created

EntryRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 41
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A countAll() 0 10 1
A getList() 0 13 1
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