Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.74% covered (success)
94.74%
36 / 38
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Office
94.74% covered (success)
94.74%
36 / 38
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%
17 / 17
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%
18 / 18
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    public ?array $sharedBookingOfficeIds = 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        ?array $sharedBookingOfficeIds = null
49    ) {
50        $this->id = $id;
51        $this->name = $name;
52        $this->address = $address;
53        $this->showAlternativeLocations = $showAlternativeLocations;
54        $this->displayNameAlternatives = $displayNameAlternatives;
55        $this->organization = $organization;
56        $this->organizationUnit = $organizationUnit;
57        $this->slotTimeInMinutes = $slotTimeInMinutes;
58        $this->geo = $geo;
59        $this->scope = $scope;
60        $this->priority = $priority;
61        $this->disabledByServices = $disabledByServices;
62        $this->slotsPerAppointment = $slotsPerAppointment;
63        $this->parentId = $parentId;
64        $this->allowDisabledServicesMix = $allowDisabledServicesMix;
65        $this->sharedBookingOfficeIds = $sharedBookingOfficeIds;
66        $this->ensureValid();
67    }
68
69    private function ensureValid()
70    {
71        if (!$this->testValid()) {
72            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
73        }
74    }
75
76    public function toArray(): array
77    {
78        return [
79            'id' => $this->id,
80            'name' => $this->name,
81            'address' => $this->address,
82            'showAlternativeLocations' => $this->showAlternativeLocations,
83            'displayNameAlternatives' => $this->displayNameAlternatives,
84            'organization' => $this->organization,
85            'organizationUnit' => $this->organizationUnit,
86            'slotTimeInMinutes' => $this->slotTimeInMinutes,
87            'geo' => $this->geo,
88            'disabledByServices' => $this->disabledByServices,
89            'priority' => $this->priority,
90            'scope' => $this->scope?->toArray(),
91            'slotsPerAppointment' => $this->slotsPerAppointment,
92            'parentId' => $this->parentId,
93            'allowDisabledServicesMix' => $this->allowDisabledServicesMix,
94            'sharedBookingOfficeIds' => $this->sharedBookingOfficeIds,
95        ];
96    }
97
98    #[\Override]
99    public function jsonSerialize(): mixed
100    {
101        return $this->toArray();
102    }
103}