Completed
Pull Request — master (#30)
by nonanerz
05:40
created

FormRequestRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 0
cbo 3
dl 6
loc 42
ccs 0
cts 33
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C selectRequestFormsByParams() 6 28 7
A selectLastRequestForms() 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\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