Completed
Push — dev ( a70858...5b49da )
by nonanerz
06:08 queued 06:04
created

SurveyRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 10 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 61.29%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 5
loc 50
ccs 19
cts 31
cp 0.6129
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findSurveyByUser() 0 10 1
B selectSurveysByParams() 5 25 5
A selectLastSurveys() 0 10 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
5
use AppBundle\Entity\Survey\Survey;
6
7
/**
8
 * SurveyRepository.
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class SurveyRepository extends \Doctrine\ORM\EntityRepository
14
{
15 2
    public function selectSurveysByParams($filter)
16
    {
17 2
        $query = $this->createQueryBuilder('Surveys')
18 2
            ->select('s, t, u')
19 2
            ->from('AppBundle:Survey\Survey', 's')
20 2
            ->join('s.type', 't')
21 2
            ->join('s.user', 'u')
22 2
            ->where('s.status = ?1')
23 2
            ->setParameter('1', 'submitted')
24 2
            ->orderBy('s.updatedAt', 'DESC');
25
26 2
        if ($filter->type && $filter->type != 'All') {
27
            $query->andWhere('t.name = ?2')
28
                ->setParameter('2', $filter->type)
29
            ;
30
        }
31
32 2 View Code Duplication
        if ($filter->start && $filter->end) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
            $query->andWhere('s.createdAt BETWEEN ?3 AND ?4')
34
                ->setParameter('3', $filter->getStart())
35
                ->setParameter('4', $filter->getEnd());
36
        }
37
38 2
        return $query->getQuery()->getResult();
39
    }
40
41
    public function selectLastSurveys()
42
    {
43
        $query = $this->createQueryBuilder('s')
44
            ->where('s.status = ?1')
45
            ->setParameter('1', 'submitted')
46
            ->orderBy('s.updatedAt', 'DESC')
47
            ->setMaxResults(5);
48
49
        return $query->getQuery()->getResult();
50
    }
51
52 2
    public function findSurveyByUser($user)
53
    {
54 2
        $query = $this->createQueryBuilder('s')
55 2
            ->where('s.user = :user')
56 2
            ->setParameter('user', $user)
57 2
            ->orderBy('s.updatedAt', 'DESC')
58 2
            ->getQuery();
59
60 2
        return $query->getResult();
61
    }
62
}
63