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

CommentRepository::getCountComments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
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