Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Month
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
5 / 5
9
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getFirstDay
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDayList
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setDays
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 createForDateFromDayList
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsentities;
4
5class Month extends Schema\Entity
6{
7    public const PRIMARY = 'month';
8
9    public $calendarDayList;
10
11    public static $schema = "month.json";
12
13    #[\Override]
14    public function getDefaults()
15    {
16        return [
17            'days' => new Collection\DayList(),
18        ];
19    }
20
21    public function getFirstDay()
22    {
23        $dateTime = Helper\DateTime::create($this['year'] . '-' . $this['month'] . '-1');
24        return $dateTime->modify('00:00:00');
25    }
26
27    public function getDayList()
28    {
29        if (!$this->days instanceof Collection\DayList) {
30            $this->days = new Collection\DayList($this->days);
31        }
32        return $this->days;
33    }
34
35    public function setDays(Collection\DayList $dayList)
36    {
37        foreach ($this->getDayList() as $key => $day) {
38            if (!$day instanceof Day) {
39                $day = new Day($day);
40            }
41            $this->days[$key] = $dayList->getDayByDay($day);
42        }
43        return $this;
44    }
45
46    public static function createForDateFromDayList(
47        \DateTimeInterface $currentDate,
48        \BO\Zmsentities\Collection\DayList $dayList
49    ) {
50        $startDow = date('w', mktime(0, 0, 0, $currentDate->format('m'), 1, $currentDate->format('Y')));
51        $monthDayList = $dayList->withAssociatedDays($currentDate);
52        $month = (new self(
53            array(
54                'year' => $currentDate->format('Y'),
55                'month' => $currentDate->format('m'),
56                'calHeadline' => \BO\Zmsentities\Helper\DateTime::getFormatedDates($currentDate, 'MMMM yyyy'),
57                'startDow' => ($startDow == 0) ? 6 : $startDow - 1, // change for week start with monday on 0,
58                'days' => $monthDayList,
59                'appointmentExists' => $monthDayList->hasDayWithAppointments(),
60            )
61        ));
62        return $month;
63    }
64}