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