Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
87.50% |
7 / 8 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
Combinable | |
87.50% |
7 / 8 |
|
80.00% |
4 / 5 |
7.10 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
getCombinations | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 Combinable extends Entity implements JsonSerializable |
12 | { |
13 | public static $schema = 'citizenapi/combinable.json'; |
14 | /** @var array<int, int[]> */ |
15 | private array $combinations = []; |
16 | /** |
17 | * Constructor. |
18 | * |
19 | * @param array $combinations An associative array of combinations (serviceId => providerIds). |
20 | */ |
21 | public function __construct(array $combinations = []) |
22 | { |
23 | foreach ($combinations as $id => $providerIds) { |
24 | $this->combinations[(int)$id] = array_map('intval', $providerIds); |
25 | $this->ensureValid(); |
26 | } |
27 | } |
28 | |
29 | private function ensureValid() |
30 | { |
31 | if (!$this->testValid()) { |
32 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); |
33 | } |
34 | } |
35 | |
36 | /** |
37 | * Get the combinations array. |
38 | * |
39 | * @return array<int, int[]> The combinations as an associative array of integers. |
40 | */ |
41 | public function getCombinations(): array |
42 | { |
43 | return $this->combinations; |
44 | } |
45 | |
46 | /** |
47 | * Converts the model data back into an array for serialization. |
48 | * |
49 | * @return array<int, int[]> The combinations as an associative array of integers. |
50 | */ |
51 | public function toArray(): array |
52 | { |
53 | return $this->combinations; |
54 | } |
55 | |
56 | public function jsonSerialize(): mixed |
57 | { |
58 | return $this->toArray(); |
59 | } |
60 | } |