GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b51e64...57b2f6 )
by Luis Ramón
13:02
created

getVisitRelatedWorkcentersByQuarters()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class WorkcenterRepository extends EntityRepository
8
{
9
    public function getVisitRelatedWorkcenters(User $user, array $quarters = null)
10
    {
11
        $em = $this->getEntityManager();
12
13 View Code Duplication
        if (null === $quarters) {
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...
14
            $quarters = [Agreement::FIRST_QUARTER, Agreement::SECOND_QUARTER, Agreement::THIRD_QUARTER];
15
        }
16
17
        $dates = $em->getRepository('AppBundle:Agreement')->getAgreementsDateRangeByEducationalTutorAndQuarters($user, $quarters);
18
19
        if ($dates[0][1] === null) {
20
            return [];
21
        }
22
23
        return $em->createQuery('SELECT DISTINCT w,
24
              (SELECT COUNT(a1) FROM AppBundle:Agreement a1 WHERE a1.workcenter = w AND a1.educationalTutor = :user AND a1.quarter IN (:quarters)),
25
              (SELECT COUNT(DISTINCT a2.student) FROM AppBundle:Agreement a2 WHERE a2.workcenter = w AND a2.educationalTutor = :user AND a2.quarter IN (:quarters)),
26
              (SELECT COUNT(v3) FROM AppBundle:Visit v3 WHERE v3.workcenter = w AND v3.tutor = :user AND v3.date >= :dateFrom AND v3.date <= :dateTo),
27
              (SELECT MAX(v4.date) FROM AppBundle:Visit v4 WHERE v4.workcenter = w AND v4.tutor = :user AND v4.date >= :dateFrom AND v4.date <= :dateTo),
28
              (SELECT MIN(v5.date) FROM AppBundle:Visit v5 WHERE v5.workcenter = w AND v5.tutor = :user AND v5.date >= :dateFrom AND v5.date <= :dateTo)
29
              FROM AppBundle:Workcenter w JOIN AppBundle:Agreement a WITH a.workcenter = w JOIN AppBundle:Company c WHERE a.educationalTutor = :user AND a.quarter IN (:quarters) ORDER BY w.name')
30
            ->setParameter('user', $user)
31
            ->setParameter('quarters', $quarters)
32
            ->setParameter('dateFrom', $dates[0][1])
33
            ->setParameter('dateTo', $dates[0][2])
34
            ->getResult();
35
    }
36
37
    public function getVisitRelatedWorkcentersByQuarters(User $user)
38
    {
39
        $quarters = [Agreement::FIRST_QUARTER, Agreement::SECOND_QUARTER, Agreement::THIRD_QUARTER];
40
41
        $result = [];
42
43
        foreach($quarters as $quarter) {
44
            $partial = $this->getVisitRelatedWorkcenters($user, [$quarter]);
45
            if ($partial) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $partial of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
46
                $result[$quarter] = $partial;
47
            }
48
        }
49
50
        return $result;
51
    }
52
53
    public function getWorkcentersByEducationTutor(User $user)
54
    {
55
        $em = $this->getEntityManager();
56
57
        return $em->createQuery('SELECT DISTINCT w
58
              FROM AppBundle:Workcenter w JOIN AppBundle:Agreement a WITH a.workcenter = w JOIN AppBundle:Company c WHERE a.educationalTutor = :user ORDER BY w.name')
59
            ->setParameter('user', $user)
60
            ->getResult();
61
    }
62
}
63