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    /**
46     * @return void
47     */
48    private function ensureValid()
49    {
50        if (!$this->testValid()) {
51            throw new InvalidArgumentException("The provided data is invalid according to the schema.");
52        }
53    }
54
55    public function toArray(): array
56    {
57        return [
58            'id' => $this->id,
59            'name' => $this->name,
60            'maxQuantity' => $this->maxQuantity,
61            'combinable' => $this->combinable,
62            'parentId' => $this->parentId,
63            'variantId' => $this->variantId,
64            'rootParentId' => $this->rootParentId,
65            'showOnStartPage' => $this->showOnStartPage
66        ];
67    }
68
69    #[\Override]
70    public function jsonSerialize(): mixed
71    {
72        return $this->toArray();
73    }
74}