Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ThinnedProvider
95.00% covered (success)
95.00%
19 / 20
75.00% covered (warning)
75.00%
3 / 4
5
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 ensureValid
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
2.50
 toArray
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Models;
6
7use BO\Zmsentities\Schema\Entity;
8use InvalidArgumentException;
9use JsonSerializable;
10
11class ThinnedProvider extends Entity implements JsonSerializable
12{
13    public static $schema = "citizenapi/thinnedProvider.json";
14    public ?int $id;
15    public ?string $name;
16    public ?string $displayName;
17    public ?string $source;
18    public ?float $lat;
19    public ?float $lon;
20    public ?ThinnedContact $contact;
21    public function __construct(?int $id = null, ?string $name = null, ?string $displayName = null, ?float $lat = null, ?float $lon = null, ?string $source = null, ?ThinnedContact $contact = null,)
22    {
23        $this->id = $id;
24        $this->name = $name;
25        $this->displayName = $displayName;
26        $this->lat = $lat;
27        $this->lon = $lon;
28        $this->source = $source;
29        $this->contact = $contact;
30        $this->ensureValid();
31    }
32
33    private function ensureValid()
34    {
35        if (!$this->testValid()) {
36            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
37        }
38    }
39
40    public function toArray(): array
41    {
42        return [
43            'id' => $this->id ?? null,
44            'name' => $this->name ?? null,
45            'displayName' => $this->displayName ?? null,
46            'lat' => $this->lat ?? null,
47            'lon' => $this->lon ?? null,
48            'source' => $this->source ?? null,
49            'contact' => $this->contact ?? null,
50        ];
51    }
52
53    #[\Override]
54    public function jsonSerialize(): mixed
55    {
56        return $this->toArray();
57    }
58}