Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
14 / 16
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OfficeServiceRelation
87.50% covered (warning)
87.50%
14 / 16
50.00% covered (danger)
50.00%
2 / 4
5.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
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%
7 / 7
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 InvalidArgumentException;
9use JsonSerializable;
10
11class OfficeServiceRelation extends Entity implements JsonSerializable
12{
13    public static $schema = 'citizenapi/officeServiceRelation.json';
14
15    public int $officeId;
16    public int $serviceId;
17    public int $slots;
18    public bool $public;
19    public ?int $maxQuantity;
20
21    public function __construct(int $officeId, int $serviceId, int $slots, bool $public, ?int $maxQuantity)
22    {
23        $this->officeId = $officeId;
24        $this->serviceId = $serviceId;
25        $this->slots = $slots;
26        $this->public = $public;
27        $this->maxQuantity = $maxQuantity;
28        $this->ensureValid();
29    }
30
31    private function ensureValid()
32    {
33        if (!$this->testValid()) {
34            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
35        }
36    }
37
38    public function toArray(): array
39    {
40        return [
41            'officeId' => $this->officeId,
42            'serviceId' => $this->serviceId,
43            'slots' => $this->slots,
44            'public' => $this->public,
45            'maxQuantity' => $this->maxQuantity,
46        ];
47    }
48
49    #[\Override]
50    public function jsonSerialize(): mixed
51    {
52        return $this->toArray();
53    }
54}