Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.75% |
30 / 32 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
Office | |
93.75% |
30 / 32 |
|
50.00% |
2 / 4 |
5.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
toArray | |
100.00% |
15 / 15 |
|
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 BO\Zmscitizenapi\Models\ThinnedScope; |
9 | use InvalidArgumentException; |
10 | use JsonSerializable; |
11 | |
12 | class Office extends Entity implements JsonSerializable |
13 | { |
14 | public static $schema = 'citizenapi/office.json'; |
15 | public int $id; |
16 | public string $name; |
17 | public ?array $address = null; |
18 | public ?array $displayNameAlternatives = null; |
19 | public ?bool $showAlternativeLocations = null; |
20 | public ?string $organization = null; |
21 | public ?string $organizationUnit = null; |
22 | public ?int $slotTimeInMinutes = null; |
23 | public ?array $geo = null; |
24 | public ?array $disabledByServices = []; |
25 | public int $priority = 1; |
26 | public ?ThinnedScope $scope = null; |
27 | public ?string $maxSlotsPerAppointment = null; |
28 | |
29 | public function __construct( |
30 | int $id, |
31 | string $name, |
32 | ?array $address = null, |
33 | ?bool $showAlternativeLocations = null, |
34 | ?array $displayNameAlternatives = null, |
35 | ?string $organization = null, |
36 | ?string $organizationUnit = null, |
37 | ?int $slotTimeInMinutes = null, |
38 | ?array $geo = null, |
39 | ?array $disabledByServices = [], |
40 | int $priority = 1, |
41 | ?ThinnedScope $scope = null, |
42 | ?string $maxSlotsPerAppointment = null |
43 | ) { |
44 | $this->id = $id; |
45 | $this->name = $name; |
46 | $this->address = $address; |
47 | $this->showAlternativeLocations = $showAlternativeLocations; |
48 | $this->displayNameAlternatives = $displayNameAlternatives; |
49 | $this->organization = $organization; |
50 | $this->organizationUnit = $organizationUnit; |
51 | $this->slotTimeInMinutes = $slotTimeInMinutes; |
52 | $this->geo = $geo; |
53 | $this->scope = $scope; |
54 | $this->priority = $priority; |
55 | $this->disabledByServices = $disabledByServices; |
56 | $this->maxSlotsPerAppointment = $maxSlotsPerAppointment; |
57 | $this->ensureValid(); |
58 | } |
59 | |
60 | private function ensureValid() |
61 | { |
62 | if (!$this->testValid()) { |
63 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); |
64 | } |
65 | } |
66 | |
67 | /** |
68 | * Converts the model data back into an array for serialization. |
69 | * |
70 | * @return array |
71 | */ |
72 | public function toArray(): array |
73 | { |
74 | return [ |
75 | 'id' => $this->id, |
76 | 'name' => $this->name, |
77 | 'address' => $this->address, |
78 | 'showAlternativeLocations' => $this->showAlternativeLocations, |
79 | 'displayNameAlternatives' => $this->displayNameAlternatives, |
80 | 'organization' => $this->organization, |
81 | 'organizationUnit' => $this->organizationUnit, |
82 | 'slotTimeInMinutes' => $this->slotTimeInMinutes, |
83 | 'geo' => $this->geo, |
84 | 'disabledByServices' => $this->disabledByServices, |
85 | 'priority' => $this->priority, |
86 | 'scope' => $this->scope?->toArray(), |
87 | 'maxSlotsPerAppointment' => $this->maxSlotsPerAppointment |
88 | ]; |
89 | } |
90 | |
91 | public function jsonSerialize(): mixed |
92 | { |
93 | return $this->toArray(); |
94 | } |
95 | } |