Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
OfficeServiceAndRelationList | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
5.12 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace BO\Zmscitizenapi\Models\Collections; |
6 | |
7 | use BO\Zmscitizenapi\Models\Collections\OfficeList; |
8 | use BO\Zmscitizenapi\Models\Collections\OfficeServiceRelationList; |
9 | use BO\Zmscitizenapi\Models\Collections\ServiceList; |
10 | use BO\Zmsentities\Schema\Entity; |
11 | use InvalidArgumentException; |
12 | use JsonSerializable; |
13 | |
14 | class OfficeServiceAndRelationList extends Entity implements JsonSerializable |
15 | { |
16 | public static $schema = "citizenapi/collections/officeServiceAndRelationList.json"; |
17 | /** @var OfficeList */ |
18 | protected OfficeList $offices; |
19 | /** @var ServiceList */ |
20 | protected ServiceList $services; |
21 | /** @var OfficeServiceRelationList */ |
22 | protected OfficeServiceRelationList $relations; |
23 | public function __construct(OfficeList $offices, ServiceList $services, OfficeServiceRelationList $relations) |
24 | { |
25 | $this->offices = $offices; |
26 | $this->services = $services; |
27 | $this->relations = $relations; |
28 | $this->ensureValid(); |
29 | } |
30 | |
31 | public function toArray(): array |
32 | { |
33 | return [ |
34 | 'offices' => $this->offices->toArray()['offices'], |
35 | 'services' => $this->services->toArray()['services'], |
36 | 'relations' => $this->relations->toArray()['relations'] |
37 | ]; |
38 | } |
39 | |
40 | private function ensureValid() |
41 | { |
42 | if (!$this->testValid()) { |
43 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); |
44 | } |
45 | } |
46 | |
47 | public function jsonSerialize(): mixed |
48 | { |
49 | return $this->toArray(); |
50 | } |
51 | } |