Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
AvailableAppointmentsByOffice
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 ensureValid
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 toArray
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Models;
6
7use BO\Zmsentities\Schema\Entity;
8use InvalidArgumentException;
9use JsonSerializable;
10
11class AvailableAppointmentsByOffice extends Entity implements JsonSerializable
12{
13    public static $schema = 'citizenapi/availableAppointmentsByOffice.json';
14
15    public function __construct(array $officeAppointments = [])
16    {
17
18        $this->officeAppointments = $officeAppointments;
19        $this->ensureValid();
20    }
21
22    private function ensureValid(): void
23    {
24        if (!$this->testValid()) {
25            throw new InvalidArgumentException('The provided data is invalid according to the schema.');
26        }
27    }
28
29    public function toArray(): array
30    {
31        return [
32            'offices' => array_map(function ($appointments, $officeId) {
33                return [
34                    'officeId' => $officeId,
35                    'appointments' => array_values($appointments)
36                ];
37            }, $this->officeAppointments, array_keys($this->officeAppointments))
38        ];
39    }
40
41    #[\Override]
42    public function jsonSerialize(): mixed
43    {
44        return $this->toArray();
45    }
46}