Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OfficeServiceAndRelationList
83.33% covered (warning)
83.33%
10 / 12
50.00% covered (danger)
50.00%
2 / 4
5.12
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
5 / 5
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
 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\Collections;
6
7use BO\Zmscitizenapi\Models\Collections\OfficeList;
8use BO\Zmscitizenapi\Models\Collections\OfficeServiceRelationList;
9use BO\Zmscitizenapi\Models\Collections\ServiceList;
10use BO\Zmsentities\Schema\Entity;
11use InvalidArgumentException;
12use JsonSerializable;
13
14class OfficeServiceAndRelationList extends Entity implements JsonSerializable
15{
16    public static $schema = "citizenapi/collections/officeServiceAndRelationList.json";
17    protected OfficeList $offices;
18    protected ServiceList $services;
19    protected OfficeServiceRelationList $relations;
20    public function __construct(OfficeList $offices, ServiceList $services, OfficeServiceRelationList $relations)
21    {
22        $this->offices = $offices;
23        $this->services = $services;
24        $this->relations = $relations;
25        $this->ensureValid();
26    }
27
28    public function toArray(): array
29    {
30        return [
31            'offices' => $this->offices->toArray()['offices'],
32            'services' => $this->services->toArray()['services'],
33            'relations' => $this->relations->toArray()['relations']
34        ];
35    }
36
37    private function ensureValid()
38    {
39        if (!$this->testValid()) {
40            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
41        }
42    }
43
44    #[\Override]
45    public function jsonSerialize(): mixed
46    {
47        return $this->toArray();
48    }
49}