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 string PRIMARY = 'month';
8
9    public $calendarDayList;
10
11    public static $schema = "month.json";
12
13    /**
14     * @return Collection\DayList[]
15     *
16     */
17    #[\Override]
18    public function getDefaults()
19    {
20        return [
21            'days' => new Collection\DayList(),
22        ];
23    }
24
25    public function getFirstDay()
26    {
27        $dateTime = Helper\DateTime::create($this['year'] . '-' . $this['month'] . '-1');
28        return $dateTime->modify('00:00:00');
29    }
30
31    public function getDayList(): Collection\DayList
32    {
33        if (!$this->days instanceof Collection\DayList) {
34            $this->days = new Collection\DayList($this->days);
35        }
36        return $this->days;
37    }
38
39    public function setDays(Collection\DayList $dayList): static
40    {
41        foreach ($this->getDayList() as $key => $day) {
42            if (!$day instanceof Day) {
43                $day = new Day($day);
44            }
45            $this->days[$key] = $dayList->getDayByDay($day);
46        }
47        return $this;
48    }
49
50    public static function createForDateFromDayList(
51        \DateTimeInterface $currentDate,
52        \BO\Zmsentities\Collection\DayList $dayList
53    ): self {
54        $startDow = date('w', mktime(0, 0, 0, $currentDate->format('m'), 1, $currentDate->format('Y')));
55        $monthDayList = $dayList->withAssociatedDays($currentDate);
56        $month = (new self(
57            array(
58                'year' => $currentDate->format('Y'),
59                'month' => $currentDate->format('m'),
60                'calHeadline' => \BO\Zmsentities\Helper\DateTime::getFormatedDates($currentDate, 'MMMM yyyy'),
61                'startDow' => ($startDow == 0) ? 6 : $startDow - 1, // change for week start with monday on 0,
62                'days' => $monthDayList,
63                'appointmentExists' => $monthDayList->hasDayWithAppointments(),
64            )
65        ));
66        return $month;
67    }
68}