Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
34 / 36
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Office
94.44% covered (success)
94.44%
34 / 36
50.00% covered (danger)
50.00%
2 / 4
5.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
16 / 16
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%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Models;
6
7use BO\Zmsentities\Schema\Entity;
8use BO\Zmscitizenapi\Models\ThinnedScope;
9use InvalidArgumentException;
10use JsonSerializable;
11
12class Office extends Entity implements JsonSerializable
13{
14    public static $schema = 'citizenapi/office.json';
15    public int $id;
16    public string $name;
17    public ?array $address = null;
18    public ?array $displayNameAlternatives = null;
19    public ?bool $showAlternativeLocations = null;
20    public ?string $organization = null;
21    public ?string $organizationUnit = null;
22    public ?int $slotTimeInMinutes = null;
23    public ?array $geo = null;
24    public ?array $disabledByServices = [];
25    public int $priority = 1;
26    public ?ThinnedScope $scope = null;
27    public ?string $slotsPerAppointment = null;
28    public ?int $parentId = null;
29    public ?array $allowDisabledServicesMix = null;
30
31    public function __construct(
32        int $id,
33        string $name,
34        ?array $address = null,
35        ?bool $showAlternativeLocations = null,
36        ?array $displayNameAlternatives = null,
37        ?string $organization = null,
38        ?string $organizationUnit = null,
39        ?int $slotTimeInMinutes = null,
40        ?array $geo = null,
41        ?array $disabledByServices = [],
42        int $priority = 1,
43        ?ThinnedScope $scope = null,
44        ?string $slotsPerAppointment = null,
45        ?int $parentId = null,
46        ?array $allowDisabledServicesMix = null
47    ) {
48        $this->id = $id;
49        $this->name = $name;
50        $this->address = $address;
51        $this->showAlternativeLocations = $showAlternativeLocations;
52        $this->displayNameAlternatives = $displayNameAlternatives;
53        $this->organization = $organization;
54        $this->organizationUnit = $organizationUnit;
55        $this->slotTimeInMinutes = $slotTimeInMinutes;
56        $this->geo = $geo;
57        $this->scope = $scope;
58        $this->priority = $priority;
59        $this->disabledByServices = $disabledByServices;
60        $this->slotsPerAppointment = $slotsPerAppointment;
61        $this->parentId = $parentId;
62        $this->allowDisabledServicesMix = $allowDisabledServicesMix;
63        $this->ensureValid();
64    }
65
66    private function ensureValid()
67    {
68        if (!$this->testValid()) {
69            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
70        }
71    }
72
73    public function toArray(): array
74    {
75        return [
76            'id' => $this->id,
77            'name' => $this->name,
78            'address' => $this->address,
79            'showAlternativeLocations' => $this->showAlternativeLocations,
80            'displayNameAlternatives' => $this->displayNameAlternatives,
81            'organization' => $this->organization,
82            'organizationUnit' => $this->organizationUnit,
83            'slotTimeInMinutes' => $this->slotTimeInMinutes,
84            'geo' => $this->geo,
85            'disabledByServices' => $this->disabledByServices,
86            'priority' => $this->priority,
87            'scope' => $this->scope?->toArray(),
88            'slotsPerAppointment' => $this->slotsPerAppointment,
89            'parentId' => $this->parentId,
90            'allowDisabledServicesMix' => $this->allowDisabledServicesMix,
91        ];
92    }
93
94    #[\Override]
95    public function jsonSerialize(): mixed
96    {
97        return $this->toArray();
98    }
99}