Completed
Pull Request — dev (#47)
by
unknown
12:10
created

SurveyRepository::findSurveyByParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 9.4285
cc 1
eloc 14
nc 1
nop 1
crap 1
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use AppBundle\Entity\DTO\SurveyFilter;
6
use AppBundle\Entity\Survey\Survey;
7
8
/**
9
 * SurveyRepository.
10
 *
11
 * This class was generated by the Doctrine ORM. Add your own custom
12
 * repository methods below.
13
 */
14
class SurveyRepository extends \Doctrine\ORM\EntityRepository
15 1
{
16
    public function selectSurveysByParams($filter)
17 1
    {
18 1
        $query = $this->createQueryBuilder('Surveys')
19 1
            ->select('s, t, u')
20 1
            ->from('AppBundle:Survey\Survey', 's')
21 1
            ->join('s.type', 't')
22 1
            ->join('s.user', 'u')
23
            ->where('s.status = ?1')
24 1
            ->setParameter('1', 'submitted')
25
            ->orderBy('s.updatedAt', 'DESC');
26 1
27
        if ($filter->type && $filter->type != 'All') {
28 1
            $query->andWhere('t.name = ?2')
29 1
                ->setParameter('2', $filter->type)
30 1
            ;
31 1
        }
32
33 1 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...
34 1
            $query->andWhere('s.createdAt BETWEEN ?3 AND ?4')
35 1
                ->setParameter('3', $filter->getStart())
36 1
                ->setParameter('4', $filter->getEnd());
37 1
        }
38 1
39 1
        return $query->getQuery()->getResult();
40 1
    }
41
42 1
    public function selectLastSurveys()
43
    {
44
        $query = $this->createQueryBuilder('s')
45 2
            ->where('s.status = ?1')
46
            ->setParameter('1', 'submitted')
47 2
            ->orderBy('s.updatedAt', "DESC")
48 2
            ->setMaxResults(5);
49 2
50 2
        return $query->getQuery()->getResult();
51 2
    }
52
53 2
    public function findSurveyByUser($user)
54
    {
55
        $query = $this->createQueryBuilder('s')
56
            ->where('s.user = :user')
57
            ->setParameter('user', $user)
58
            ->orderBy('s.updatedAt', 'DESC')
59
            ->getQuery();
60
61
        return $query->getResult();
62
    }
63
}
64