Lines
95.00%
19 / 20
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __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 | ||
| 11 | class 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 | /** | |
| 34 | * @return void | |
| 35 | */ | |
| 36 | private function ensureValid() | |
| 37 | { | |
| 38 | if (!$this->testValid()) { | |
| 39 | throw new InvalidArgumentException("The provided data is invalid according to the schema."); | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | public function toArray(): array | |
| 44 | { | |
| 45 | return [ | |
| 46 | 'id' => $this->id ?? null, | |
| 47 | 'name' => $this->name ?? null, | |
| 48 | 'displayName' => $this->displayName ?? null, | |
| 49 | 'lat' => $this->lat ?? null, | |
| 50 | 'lon' => $this->lon ?? null, | |
| 51 | 'source' => $this->source ?? null, | |
| 52 | 'contact' => $this->contact ?? null, | |
| 53 | ]; | |
| 54 | } | |
| 55 | ||
| 56 | #[\Override] | |
| 57 | public function jsonSerialize(): mixed | |
| 58 | { | |
| 59 | return $this->toArray(); | |
| 60 | } | |
| 61 | } |