Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
20 / 22
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Service
90.91% covered (success)
90.91%
20 / 22
50.00% covered (danger)
50.00%
2 / 4
5.02
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
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%
10 / 10
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\Zmscitizenapi\Models\Combinable;
8use BO\Zmsentities\Schema\Entity;
9use InvalidArgumentException;
10use JsonSerializable;
11
12class Service extends Entity implements JsonSerializable
13{
14    public static $schema = 'citizenapi/service.json';
15    public int $id;
16    public string $name;
17    public ?int $maxQuantity = null;
18    public ?Combinable $combinable = null;
19    public ?int $parentId = null;
20    public ?int $variantId = null;
21    public ?int $rootParentId = null;
22    public ?bool $showOnStartPage = null;
23
24    public function __construct(
25        int $id,
26        string $name,
27        ?int $maxQuantity = null,
28        ?Combinable $combinable = null,
29        ?int $parentId = null,
30        ?int $variantId = null,
31        ?bool $showOnStartPage = null,
32        ?int $rootParentId = null
33    ) {
34        $this->id = $id;
35        $this->name = $name;
36        $this->maxQuantity = $maxQuantity;
37        $this->combinable = $combinable;
38        $this->parentId = $parentId;
39        $this->variantId = $variantId;
40        $this->showOnStartPage = $showOnStartPage;
41        $this->rootParentId = $rootParentId ?? $id;
42        $this->ensureValid();
43    }
44
45    private function ensureValid()
46    {
47        if (!$this->testValid()) {
48            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
49        }
50    }
51
52    public function toArray(): array
53    {
54        return [
55            'id' => $this->id,
56            'name' => $this->name,
57            'maxQuantity' => $this->maxQuantity,
58            'combinable' => $this->combinable,
59            'parentId' => $this->parentId,
60            'variantId' => $this->variantId,
61            'rootParentId' => $this->rootParentId,
62            'showOnStartPage' => $this->showOnStartPage
63        ];
64    }
65
66    #[\Override]
67    public function jsonSerialize(): mixed
68    {
69        return $this->toArray();
70    }
71}