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    /** @var int[]|null Group of office IDs; JumpIn with one auto-selects equivalent in group */
30    public ?array $allowDisabledServicesMix = null;
31
32    public function __construct(
33        int $id,
34        string $name,
35        ?array $address = null,
36        ?bool $showAlternativeLocations = null,
37        ?array $displayNameAlternatives = null,
38        ?string $organization = null,
39        ?string $organizationUnit = null,
40        ?int $slotTimeInMinutes = null,
41        ?array $geo = null,
42        ?array $disabledByServices = [],
43        int $priority = 1,
44        ?ThinnedScope $scope = null,
45        ?string $slotsPerAppointment = null,
46        ?int $parentId = null,
47        ?array $allowDisabledServicesMix = null
48    ) {
49        $this->id = $id;
50        $this->name = $name;
51        $this->address = $address;
52        $this->showAlternativeLocations = $showAlternativeLocations;
53        $this->displayNameAlternatives = $displayNameAlternatives;
54        $this->organization = $organization;
55        $this->organizationUnit = $organizationUnit;
56        $this->slotTimeInMinutes = $slotTimeInMinutes;
57        $this->geo = $geo;
58        $this->scope = $scope;
59        $this->priority = $priority;
60        $this->disabledByServices = $disabledByServices;
61        $this->slotsPerAppointment = $slotsPerAppointment;
62        $this->parentId = $parentId;
63        $this->allowDisabledServicesMix = $allowDisabledServicesMix;
64        $this->ensureValid();
65    }
66
67    private function ensureValid()
68    {
69        if (!$this->testValid()) {
70            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
71        }
72    }
73
74    /**
75     * Converts the model data back into an array for serialization.
76     *
77     * @return array
78     */
79    public function toArray(): array
80    {
81        return [
82            'id' => $this->id,
83            'name' => $this->name,
84            'address' => $this->address,
85            'showAlternativeLocations' => $this->showAlternativeLocations,
86            'displayNameAlternatives' => $this->displayNameAlternatives,
87            'organization' => $this->organization,
88            'organizationUnit' => $this->organizationUnit,
89            'slotTimeInMinutes' => $this->slotTimeInMinutes,
90            'geo' => $this->geo,
91            'disabledByServices' => $this->disabledByServices,
92            'priority' => $this->priority,
93            'scope' => $this->scope?->toArray(),
94            'slotsPerAppointment' => $this->slotsPerAppointment,
95            'parentId' => $this->parentId,
96            'allowDisabledServicesMix' => $this->allowDisabledServicesMix,
97        ];
98    }
99
100    public function jsonSerialize(): mixed
101    {
102        return $this->toArray();
103    }
104}