Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
14 / 16 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| OfficeServiceRelation | |
87.50% |
14 / 16 |
|
50.00% |
2 / 4 |
5.05 | |
0.00% |
0 / 1 |
| __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 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace BO\Zmscitizenapi\Models; |
| 6 | |
| 7 | use BO\Zmsentities\Schema\Entity; |
| 8 | use InvalidArgumentException; |
| 9 | use JsonSerializable; |
| 10 | |
| 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 | /** |
| 22 | * Constructor. |
| 23 | * |
| 24 | * @param int $officeId |
| 25 | * @param int $serviceId |
| 26 | * @param int $slots |
| 27 | * @param bool $public |
| 28 | * @param ?int $maxQuantity |
| 29 | */ |
| 30 | public function __construct(int $officeId, int $serviceId, int $slots, bool $public, ?int $maxQuantity) |
| 31 | { |
| 32 | $this->officeId = $officeId; |
| 33 | $this->serviceId = $serviceId; |
| 34 | $this->slots = $slots; |
| 35 | $this->public = $public; |
| 36 | $this->maxQuantity = $maxQuantity; |
| 37 | $this->ensureValid(); |
| 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 | /** |
| 48 | * Converts the model data back into an array for serialization. |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | public function toArray(): array |
| 53 | { |
| 54 | return [ |
| 55 | 'officeId' => $this->officeId, |
| 56 | 'serviceId' => $this->serviceId, |
| 57 | 'slots' => $this->slots, |
| 58 | 'public' => $this->public, |
| 59 | 'maxQuantity' => $this->maxQuantity, |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Implements JSON serialization. |
| 65 | * |
| 66 | * @return mixed |
| 67 | */ |
| 68 | public function jsonSerialize(): mixed |
| 69 | { |
| 70 | return $this->toArray(); |
| 71 | } |
| 72 | } |