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