Completed
Pull Request — master (#30)
by nonanerz
04:14
created

selectRequestFormsByParams()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 28
Code Lines 15

Duplication

Lines 6
Ratio 21.43 %

Code Coverage

Tests 0
CRAP Score 56

Importance

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