Completed
Push — develop ( 6d3372...82247e )
by Victor
02:40
created

CommentRepository::getArticleComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 16
loc 16
ccs 13
cts 13
cp 1
rs 9.4285
cc 1
eloc 13
nc 1
nop 3
crap 1
1
<?php
2
3
namespace AppBundle\Repository;
4
use AppBundle\Model\PaginatorWithPages;
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * CommentRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class CommentRepository extends EntityRepository
14
{
15 5 View Code Duplication
    public function getRecentComments($page = 1, $max = 5)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17 5
        $first = $max * ($page - 1);
18 5
        $query = $this->createQueryBuilder('c')
19 5
            ->select('c, a, u')
20 5
            ->join('c.article', 'a')
21 5
            ->join('c.user', 'u')
22 5
            ->orderBy('c.createdAt', 'DESC')
23 5
            ->setFirstResult($first)
24 5
            ->setMaxResults($max)
25 5
            ->getQuery();
26
27 5
        return new PaginatorWithPages($query, $fetchJoinCollection = true);
28
    }
29
30 2 View Code Duplication
    public function getArticleComment($slug, $page = 1, $max = 5)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32 2
        $first = $max * ($page - 1);
33 2
        $query = $this->createQueryBuilder('c')
34 2
            ->select('c, a, u')
35 2
            ->join('c.article', 'a')
36 2
            ->where('a.slug = ?1')
37 2
            ->join('c.user', 'u')
38 2
            ->orderBy('c.createdAt', 'DESC')
39 2
            ->setFirstResult($first)
40 2
            ->setMaxResults($max)
41 2
            ->setParameter(1, $slug)
42 2
            ->getQuery();
43
44 2
        return new PaginatorWithPages($query, $fetchJoinCollection = true);
45
    }
46
47
    public function getCountComments()
48
    {
49
        return $this->createQueryBuilder('c')
50
            ->select('count(c.id) as countComments')
51
            ->getQuery()
52
            ->getSingleResult();
53
    }
54
}
55