Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
75.00% |
6 / 8 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
AvailableAppointments | |
75.00% |
6 / 8 |
|
50.00% |
2 / 4 |
5.39 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
toArray | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
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 AvailableAppointments extends Entity implements JsonSerializable |
12 | { |
13 | public static $schema = 'citizenapi/availableAppointments.json'; |
14 | /** @var array */ |
15 | public array $appointmentTimestamps = []; |
16 | public function __construct(array $appointmentTimestamps = []) |
17 | { |
18 | $this->appointmentTimestamps = array_map('intval', $appointmentTimestamps); |
19 | $this->ensureValid(); |
20 | } |
21 | |
22 | private function ensureValid() |
23 | { |
24 | if (!$this->testValid()) { |
25 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); |
26 | } |
27 | } |
28 | |
29 | /** |
30 | * Converts the model data back into an array for serialization. |
31 | * |
32 | * @return array |
33 | */ |
34 | public function toArray(): array |
35 | { |
36 | return [ |
37 | 'appointmentTimestamps' => $this->appointmentTimestamps, |
38 | ]; |
39 | } |
40 | |
41 | public function jsonSerialize(): mixed |
42 | { |
43 | return $this->toArray(); |
44 | } |
45 | } |