Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.00% |
19 / 20 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
ThinnedProvider | |
95.00% |
19 / 20 |
|
75.00% |
3 / 4 |
5 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
ensureValid | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
toArray | |
100.00% |
9 / 9 |
|
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 ThinnedProvider extends Entity implements JsonSerializable |
12 | { |
13 | public static $schema = "citizenapi/thinnedProvider.json"; |
14 | /** @var int|null */ |
15 | public ?int $id; |
16 | /** @var string|null */ |
17 | public ?string $name; |
18 | /** @var string|null */ |
19 | public ?string $displayName; |
20 | /** @var string|null */ |
21 | public ?string $source; |
22 | /** @var float|null */ |
23 | public ?float $lat; |
24 | /** @var float|null */ |
25 | public ?float $lon; |
26 | /** @var ThinnedContact|null */ |
27 | public ?ThinnedContact $contact; |
28 | public function __construct(?int $id = null, ?string $name = null, ?string $displayName = null, ?float $lat = null, ?float $lon = null, ?string $source = null, ?ThinnedContact $contact = null,) |
29 | { |
30 | $this->id = $id; |
31 | $this->name = $name; |
32 | $this->displayName = $displayName; |
33 | $this->lat = $lat; |
34 | $this->lon = $lon; |
35 | $this->source = $source; |
36 | $this->contact = $contact; |
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 | * Convert the ThinnedProvider object to an array. |
49 | * |
50 | * @return array |
51 | */ |
52 | public function toArray(): array |
53 | { |
54 | return [ |
55 | 'id' => $this->id ?? null, |
56 | 'name' => $this->name ?? null, |
57 | 'displayName' => $this->displayName ?? null, |
58 | 'lat' => $this->lat ?? null, |
59 | 'lon' => $this->lon ?? null, |
60 | 'source' => $this->source ?? null, |
61 | 'contact' => $this->contact ?? null, |
62 | ]; |
63 | } |
64 | |
65 | public function jsonSerialize(): mixed |
66 | { |
67 | return $this->toArray(); |
68 | } |
69 | } |