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

CommentRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 71.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 82.76%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 3
c 5
b 0
f 1
lcom 1
cbo 3
dl 30
loc 42
ccs 24
cts 29
cp 0.8276
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecentComments() 14 14 1
A getArticleComment() 16 16 1
A getCountComments() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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