Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AppointmentList
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
4 / 4
12
100.00% covered (success)
100.00%
1 / 1
 getByDate
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
 hasDateScope
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 hasAppointment
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getCalculatedSlotCount
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsentities\Collection;
4
5use BO\Zmsentities\Appointment;
6
7/**
8 * @extends Base<\BO\Zmsentities\Appointment>
9 */
10class AppointmentList extends Base
11{
12    public const string ENTITY_CLASS = '\BO\Zmsentities\Appointment';
13
14    public function getByDate(mixed $date): Appointment|false
15    {
16        foreach ($this as $item) {
17            if ($item['date'] == $date) {
18                /** @psalm-suppress RedundantCondition Runtime arrays can bypass ENTITY_CLASS. */
19                return $item instanceof Appointment ? $item : new Appointment($item);
20            }
21        }
22        return false;
23    }
24
25    public function hasDateScope(mixed $date, mixed $scopeId): bool
26    {
27        $item = $this->getByDate($date);
28        if ($item && $item->toProperty()->scope->id->get() == $scopeId) {
29            return true;
30        }
31        return false;
32    }
33
34    public function hasAppointment(\BO\Zmsentities\Appointment $appointment): bool
35    {
36        foreach ($this as $appointmentItem) {
37            if ($appointmentItem->isMatching($appointment)) {
38                return true;
39            }
40        }
41        return false;
42    }
43
44    public function getCalculatedSlotCount(): mixed
45    {
46        $slotCount = 0;
47        foreach ($this as $appointmentItem) {
48            $slotCount += $appointmentItem->getSlotCount();
49        }
50        return $slotCount;
51    }
52}