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 ( d5799b...6b6569 )
by Luis Ramón
02:58
created

WorkdayRepository::createCalendar()   C

Complexity

Conditions 9
Paths 14

Size

Total Lines 48
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 48
rs 5.5102
cc 9
eloc 36
nc 14
nop 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Form\Model\Calendar;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\EntityRepository;
8
9
class WorkdayRepository extends EntityRepository
10
{
11
    public function createCalendar(Calendar $calendar, Agreement $agreement)
12
    {
13
        $date = $calendar->getStartDate();
14
        $hours = $calendar->getTotalHours();
15
        $nonSchoolDays = $this->getEntityManager()->getRepository('AppBundle:NonSchoolDay')
16
            ->createQueryBuilder('n')
17
            ->select('n.date')
18
            ->getQuery()->getArrayResult();
19
20
        $nonSchoolDays = array_map('current', $nonSchoolDays);
21
22
        $collection = new ArrayCollection();
23
24
        while ($hours > 0) {
25
            if (false === in_array($date, $nonSchoolDays, false)) {
26
                $current = new Workday();
27
                $current->setDate(clone $date);
28
                $current->setAgreement($agreement);
29
                switch ($date->format('w')) {
30
                    case 1:
31
                        $current->setHours(min($hours, $calendar->getHoursMon()));
32
                        break;
33
                    case 2:
34
                        $current->setHours(min($hours, $calendar->getHoursTue()));
35
                        break;
36
                    case 3:
37
                        $current->setHours(min($hours, $calendar->getHoursWed()));
38
                        break;
39
                    case 4:
40
                        $current->setHours(min($hours, $calendar->getHoursThu()));
41
                        break;
42
                    case 5:
43
                        $current->setHours(min($hours, $calendar->getHoursFri()));
44
                        break;
45
                }
46
47
                $hours -= $current->getHours();
48
49
                if ($current->getHours()) {
50
                    $collection->add($current);
51
                    $this->getEntityManager()->persist($current);
52
                }
53
            }
54
55
            $date->add(new \DateInterval('P1D'));
56
        }
57
        return $collection;
58
    }
59
}
60