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/** @var array|null */
15    public array|null $officeAppointments = [];
16/**
17     * @param array $officeAppointments
18     */
19    public function __construct(array $officeAppointments = [])
20    {
21
22        $this->officeAppointments = $officeAppointments;
23        $this->ensureValid();
24    }
25
26    private function ensureValid(): void
27    {
28        if (!$this->testValid()) {
29            throw new InvalidArgumentException('The provided data is invalid according to the schema.');
30        }
31    }
32
33    /**
34     * Converts the model data back into an array for serialization.
35     *
36     * @return array
37     */
38    public function toArray(): array
39    {
40        return [
41            'offices' => array_map(function ($appointments, $officeId) {
42
43                return [
44                    'officeId' => $officeId,
45                    'appointments' => $appointments
46                ];
47            }, $this->officeAppointments, array_keys($this->officeAppointments))
48        ];
49    }
50
51    /**
52     * Implementation of JsonSerializable.
53     */
54    public function jsonSerialize(): mixed
55    {
56        return $this->toArray();
57    }
58}