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 — user-entity ( e96cee...7b48d2 )
by Luis Ramón
02:43
created

AgreementRepository   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
c 4
b 0
f 0
lcom 1
cbo 5
dl 18
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A countHours() 0 7 1
A getRealFromDate() 9 9 2
A getRealToDate() 9 9 2
A getActivitiesStats() 0 12 1
A delete() 0 18 3

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\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class AgreementRepository extends EntityRepository
8
{
9
    public function countHours(Agreement $agreement)
10
    {
11
        return $this->getEntityManager()
12
            ->createQuery('SELECT SUM(w.hours) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
13
            ->setParameter('agreement', $agreement)
14
            ->getSingleScalarResult();
15
    }
16
17 View Code Duplication
    public function getRealFromDate(Agreement $agreement)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
18
    {
19
        $date = $this->getEntityManager()
20
            ->createQuery('SELECT MIN(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
21
            ->setParameter('agreement', $agreement)
22
            ->getSingleScalarResult();
23
24
        return null === $date ?: new \DateTime($date);
25
    }
26
27 View Code Duplication
    public function getRealToDate(Agreement $agreement)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
28
    {
29
        $date = $this->getEntityManager()
30
            ->createQuery('SELECT MAX(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
31
            ->setParameter('agreement', $agreement)
32
            ->getSingleScalarResult();
33
34
        return null === $date ?: new \DateTime($date);
35
    }
36
37
    public function getActivitiesStats(Agreement $agreement)
38
    {
39
        $activities = $agreement->getActivities();
40
41
        $result = $this->getEntityManager()
42
            ->createQuery('SELECT a, SUM(t.hours), COUNT(a) FROM AppBundle:Activity a INNER JOIN AppBundle:Tracking t WITH t.activity = a.id INNER JOIN t.workday w WHERE w.agreement = :agreement AND a.id IN (:activities) GROUP BY a.id')
43
            ->setParameter('agreement', $agreement)
44
            ->setParameter('activities', $activities)
45
            ->getResult();
46
47
        return $result;
48
    }
49
50
    public function delete(Agreement $agreement)
51
    {
52
        // borrar informe si estaba cumplimentado
53
        if ($agreement->getReport()) {
54
            $this->getEntityManager()->remove($agreement->getReport());
55
        }
56
57
        // borrar calendario
58
        foreach ($agreement->getWorkdays() as $workday) {
59
            $this->getEntityManager()->remove($workday);
60
        }
61
62
        // borrar actividades de plan de formación individualizado
63
        $agreement->getActivities()->clear();
64
65
        // borrar acuerdo
66
        $this->getEntityManager()->remove($agreement);
67
    }
68
}
69