CategoryRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 31
ccs 0
cts 23
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 8 1
A paginated() 0 8 1
A last() 0 10 1
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