Lines
87.50%
14 / 16
Methods
50.00%
2 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | ||
| ensureValid | 50.00% | 1 / 2 | 0.00% | 0 / 1 | 2.50 | ||
| toArray | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 1 | ||
| jsonSerialize | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| 11 | class OfficeServiceRelation extends Entity implements JsonSerializable | |
| 12 | { | |
| 13 | public static $schema = 'citizenapi/officeServiceRelation.json'; | |
| 14 | ||
| 15 | public int $officeId; | |
| 16 | public int $serviceId; | |
| 17 | public int $slots; | |
| 18 | public bool $public; | |
| 19 | public ?int $maxQuantity; | |
| 20 | ||
| 21 | public function __construct(int $officeId, int $serviceId, int $slots, bool $public, ?int $maxQuantity) | |
| 22 | { | |
| 23 | $this->officeId = $officeId; | |
| 24 | $this->serviceId = $serviceId; | |
| 25 | $this->slots = $slots; | |
| 26 | $this->public = $public; | |
| 27 | $this->maxQuantity = $maxQuantity; | |
| 28 | $this->ensureValid(); | |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * @return void | |
| 33 | */ | |
| 34 | private function ensureValid() | |
| 35 | { | |
| 36 | if (!$this->testValid()) { | |
| 37 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | public function toArray(): array | |
| 42 | { | |
| 43 | return [ | |
| 44 | 'officeId' => $this->officeId, | |
| 45 | 'serviceId' => $this->serviceId, | |
| 46 | 'slots' => $this->slots, | |
| 47 | 'public' => $this->public, | |
| 48 | 'maxQuantity' => $this->maxQuantity, | |
| 49 | ]; | |
| 50 | } | |
| 51 | ||
| 52 | #[\Override] | |
| 53 | public function jsonSerialize(): mixed | |
| 54 | { | |
| 55 | return $this->toArray(); | |
| 56 | } | |
| 57 | } |