Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
6 / 8
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
AvailableAppointments
75.00% covered (warning)
75.00%
6 / 8
50.00% covered (danger)
50.00%
2 / 4
5.39
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 ensureValid
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
2.50
 toArray
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 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 AvailableAppointments extends Entity implements JsonSerializable
12{
13    public static $schema = 'citizenapi/availableAppointments.json';
14    public array $appointmentTimestamps = [];
15
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    public function toArray(): array
30    {
31        return [
32            'appointmentTimestamps' => $this->appointmentTimestamps,
33        ];
34    }
35
36    #[\Override]
37    public function jsonSerialize(): mixed
38    {
39        return $this->toArray();
40    }
41}