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    /**
32     * @return void
33     */
34    private function ensureValid()
35    {
36        if (!$this->testValid()) {
37            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
38        }
39    }
40
41    public function toArray(): array
42    {
43        return [
44            'officeId' => $this->officeId,
45            'serviceId' => $this->serviceId,
46            'slots' => $this->slots,
47            'public' => $this->public,
48            'maxQuantity' => $this->maxQuantity,
49        ];
50    }
51
52    #[\Override]
53    public function jsonSerialize(): mixed
54    {
55        return $this->toArray();
56    }
57}