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