Lines
83.33%
10 / 12
Methods
50.00%
2 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __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 | ||
| 14 | class OfficeServiceAndRelationList extends Entity implements JsonSerializable | |
| 15 | { | |
| 16 | public static $schema = "citizenapi/collections/officeServiceAndRelationList.json"; | |
| 17 | protected OfficeList $offices; | |
| 18 | protected ServiceList $services; | |
| 19 | protected OfficeServiceRelationList $relations; | |
| 20 | public function __construct(OfficeList $offices, ServiceList $services, OfficeServiceRelationList $relations) | |
| 21 | { | |
| 22 | $this->offices = $offices; | |
| 23 | $this->services = $services; | |
| 24 | $this->relations = $relations; | |
| 25 | $this->ensureValid(); | |
| 26 | } | |
| 27 | ||
| 28 | public function toArray(): array | |
| 29 | { | |
| 30 | return [ | |
| 31 | 'offices' => $this->offices->toArray()['offices'], | |
| 32 | 'services' => $this->services->toArray()['services'], | |
| 33 | 'relations' => $this->relations->toArray()['relations'] | |
| 34 | ]; | |
| 35 | } | |
| 36 | ||
| 37 | /** | |
| 38 | * @return void | |
| 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 | #[\Override] | |
| 48 | public function jsonSerialize(): mixed | |
| 49 | { | |
| 50 | return $this->toArray(); | |
| 51 | } | |
| 52 | } |