Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
OfficeServiceRelation | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
5.12 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
toArray | |
100.00% |
5 / 5 |
|
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 | /** @var int */ |
15 | public int $officeId; |
16 | /** @var int */ |
17 | public int $serviceId; |
18 | /** @var int */ |
19 | public int $slots; |
20 | /** |
21 | * Constructor. |
22 | * |
23 | * @param int $officeId |
24 | * @param int $serviceId |
25 | * @param int $slots |
26 | */ |
27 | public function __construct(int $officeId, int $serviceId, int $slots) |
28 | { |
29 | $this->officeId = $officeId; |
30 | $this->serviceId = $serviceId; |
31 | $this->slots = $slots; |
32 | $this->ensureValid(); |
33 | } |
34 | |
35 | private function ensureValid() |
36 | { |
37 | if (!$this->testValid()) { |
38 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); |
39 | } |
40 | } |
41 | |
42 | /** |
43 | * Converts the model data back into an array for serialization. |
44 | * |
45 | * @return array |
46 | */ |
47 | public function toArray(): array |
48 | { |
49 | return [ |
50 | 'officeId' => $this->officeId, |
51 | 'serviceId' => $this->serviceId, |
52 | 'slots' => $this->slots, |
53 | ]; |
54 | } |
55 | |
56 | /** |
57 | * Implements JSON serialization. |
58 | * |
59 | * @return mixed |
60 | */ |
61 | public function jsonSerialize(): mixed |
62 | { |
63 | return $this->toArray(); |
64 | } |
65 | } |