Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ThinnedContact
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 ensureValid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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;
9
10class ThinnedContact extends Entity implements \JsonSerializable
11{
12    /** @var string Points to the JSON schema file for validation */
13    public static $schema = 'citizenapi/thinnedContact.json';
14    public ?string $city;
15    public ?string $country;
16    public ?string $name;
17    public ?string $postalCode;
18    public ?string $region;
19    public ?string $street;
20    public ?string $streetNumber;
21    public function __construct(?string $city = null, ?string $country = null, ?string $name = null, ?string $postalCode = null, ?string $region = null, ?string $street = null, ?string $streetNumber = null)
22    {
23        $this->city         = $city     ?? '';
24        $this->country      = $country  ?? '';
25        $this->name         = $name     ?? '';
26        $this->postalCode   = $postalCode ?? '';
27        $this->region       = $region   ?? '';
28        $this->street       = $street   ?? '';
29        $this->streetNumber = $streetNumber ?? '';
30        $this->ensureValid();
31    }
32
33    /**
34     * Validates the model against the JSON schema.
35     *
36     * @throws InvalidArgumentException if validation fails.
37     */
38    private function ensureValid(): void
39    {
40        // testValid() is inherited from Entity; it checks $this against self::$schema.
41        $this->testValid();
42    }
43
44    public function toArray(): array
45    {
46        return [
47            'city'         => $this->city,
48            'country'      => $this->country,
49            'name'         => $this->name,
50            'postalCode'   => $this->postalCode,
51            'region'       => $this->region,
52            'street'       => $this->street,
53            'streetNumber' => $this->streetNumber,
54        ];
55    }
56
57    public function jsonSerialize(): mixed
58    {
59        return $this->toArray();
60    }
61}