Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.12% covered (success)
94.12%
32 / 34
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Office
94.12% covered (success)
94.12%
32 / 34
50.00% covered (danger)
50.00%
2 / 4
5.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
15 / 15
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%
16 / 16
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 $maxSlotsPerAppointment = null;
28    public ?int $parentId = null;
29
30    public function __construct(
31        int $id,
32        string $name,
33        ?array $address = null,
34        ?bool $showAlternativeLocations = null,
35        ?array $displayNameAlternatives = null,
36        ?string $organization = null,
37        ?string $organizationUnit = null,
38        ?int $slotTimeInMinutes = null,
39        ?array $geo = null,
40        ?array $disabledByServices = [],
41        int $priority = 1,
42        ?ThinnedScope $scope = null,
43        ?string $maxSlotsPerAppointment = null,
44        ?int $parentId = null
45    ) {
46        $this->id = $id;
47        $this->name = $name;
48        $this->address = $address;
49        $this->showAlternativeLocations = $showAlternativeLocations;
50        $this->displayNameAlternatives = $displayNameAlternatives;
51        $this->organization = $organization;
52        $this->organizationUnit = $organizationUnit;
53        $this->slotTimeInMinutes = $slotTimeInMinutes;
54        $this->geo = $geo;
55        $this->scope = $scope;
56        $this->priority = $priority;
57        $this->disabledByServices = $disabledByServices;
58        $this->maxSlotsPerAppointment = $maxSlotsPerAppointment;
59        $this->parentId = $parentId;
60        $this->ensureValid();
61    }
62
63    private function ensureValid()
64    {
65        if (!$this->testValid()) {
66            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
67        }
68    }
69
70    /**
71     * Converts the model data back into an array for serialization.
72     *
73     * @return array
74     */
75    public function toArray(): array
76    {
77        return [
78            'id' => $this->id,
79            'name' => $this->name,
80            'address' => $this->address,
81            'showAlternativeLocations' => $this->showAlternativeLocations,
82            'displayNameAlternatives' => $this->displayNameAlternatives,
83            'organization' => $this->organization,
84            'organizationUnit' => $this->organizationUnit,
85            'slotTimeInMinutes' => $this->slotTimeInMinutes,
86            'geo' => $this->geo,
87            'disabledByServices' => $this->disabledByServices,
88            'priority' => $this->priority,
89            'scope' => $this->scope?->toArray(),
90            'maxSlotsPerAppointment' => $this->maxSlotsPerAppointment,
91            'parentId' => $this->parentId
92        ];
93    }
94
95    public function jsonSerialize(): mixed
96    {
97        return $this->toArray();
98    }
99}