Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AvailableAppointmentsByOffice | |
0.00% |
0 / 13 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| ensureValid | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| toArray | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace BO\Zmscitizenapi\Models; |
| 6 | |
| 7 | use BO\Zmsentities\Schema\Entity; |
| 8 | use InvalidArgumentException; |
| 9 | use JsonSerializable; |
| 10 | |
| 11 | class 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 | return [ |
| 43 | 'officeId' => $officeId, |
| 44 | 'appointments' => array_values($appointments) |
| 45 | ]; |
| 46 | }, $this->officeAppointments, array_keys($this->officeAppointments)) |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Implementation of JsonSerializable. |
| 52 | */ |
| 53 | public function jsonSerialize(): mixed |
| 54 | { |
| 55 | return $this->toArray(); |
| 56 | } |
| 57 | } |