Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ThinnedProvider
94.44% covered (success)
94.44%
17 / 18
75.00% covered (warning)
75.00%
3 / 4
5.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
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%
8 / 8
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/** @var int|null */
15    public ?int $id;
16/** @var string|null */
17    public ?string $name;
18/** @var string|null */
19    public ?string $source;
20/** @var float|null */
21    public ?float $lat;
22/** @var float|null */
23    public ?float $lon;
24/** @var ThinnedContact|null */
25    public ?ThinnedContact $contact;
26    public function __construct(?int $id = null, ?string $name = null, ?float $lat = null, ?float $lon = null, ?string $source = null, ?ThinnedContact $contact = null,)
27    {
28        $this->id = $id;
29        $this->name = $name;
30        $this->lat = $lat;
31        $this->lon = $lon;
32        $this->source = $source;
33        $this->contact = $contact;
34        $this->ensureValid();
35    }
36
37    private function ensureValid()
38    {
39        if (!$this->testValid()) {
40            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
41        }
42    }
43
44    /**
45     * Convert the ThinnedProvider object to an array.
46     *
47     * @return array
48     */
49    public function toArray(): array
50    {
51        return [
52            'id' => $this->id ?? null,
53            'name' => $this->name ?? null,
54            'lat' => $this->lat ?? null,
55            'lon' => $this->lon ?? null,
56            'source' => $this->source ?? null,
57            'contact' => $this->contact ?? null,
58        ];
59    }
60
61    public function jsonSerialize(): mixed
62    {
63        return $this->toArray();
64    }
65}