CategoryRepository::paginated()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Albert221\Blog\Repository\Database;
4
5
use Albert221\Blog\Repository\CategoryRepositoryInterface;
6
use Doctrine\Common\Collections\Criteria;
7
use Doctrine\ORM\EntityRepository;
8
9
class CategoryRepository extends EntityRepository implements CategoryRepositoryInterface
10
{
11
    public function count()
12
    {
13
        $query = $this->createQueryBuilder('c')
14
            ->select('count(c.id)')
15
            ->getQuery();
16
17
        return $query->getSingleScalarResult();
18
    }
19
20
    public function paginated(Criteria $criteria)
21
    {
22
        $query = $this->createQueryBuilder('c')
23
            ->addCriteria($criteria)
24
            ->getQuery();
25
26
        return $query->getResult();
27
    }
28
29
    public function last($count)
30
    {
31
        $query = $this->createQueryBuilder('c')
32
            ->join('c.posts', 'p')
33
            ->orderBy('p.published_at', 'DESC')
34
            ->setMaxResults($count)
35
            ->getQuery();
36
        
37
        return $query->getResult();
38
    }
39
}
40