Lines 90.00% 27 / 30
Functions and Methods 75.00% 9 / 12
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Request 90.00% 27 / 30 75.00% 9 / 12 21.44 0.00% 0 / 1
 getDefaults 100.00% 8 / 8 100.00% 1 / 1 1
 withReference 100.00% 4 / 4 100.00% 1 / 1 1
 hasAppointmentFromProviderData 100.00% 6 / 6 100.00% 1 / 1 8
 getSource 100.00% 1 / 1 100.00% 1 / 1 1
 getGroup 100.00% 1 / 1 100.00% 1 / 1 1
 getLink 100.00% 1 / 1 100.00% 1 / 1 1
 getName 100.00% 1 / 1 100.00% 1 / 1 1
 getAdditionalData 100.00% 1 / 1 100.00% 1 / 1 1
 getParentId 0.00% 0 / 1 0.00% 0 / 1 2
 getRootParentId 100.00% 4 / 4 100.00% 1 / 1 3
 getVariantId 0.00% 0 / 1 0.00% 0 / 1 2
 __toString 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3namespace BO\Zmsentities;
4
5class Request extends Schema\Entity
6{
7    public const string PRIMARY = 'id';
8
9    public static $schema = "request.json";
10
11    /**
12     * @return (null|string)[]
13     *
14     */
15    #[\Override]
16    public function getDefaults()
17    {
18        return [
19            'id' => '',
20            'name' => '',
21            'source' => 'dldb',
22            'parent_id' => null,
23            'root_parent_id' => null,
24            'variant_id' => null
25        ];
26    }
27
28    #[\Override]
29    public function withReference($additionalData = []): self|array
30    {
31        $additionalData['id'] = $this->getId();
32        $additionalData['name'] = $this->getName();
33        /** @var self|array $referenced */
34        $referenced = parent::withReference($additionalData);
35        return $referenced;
36    }
37
38    public function hasAppointmentFromProviderData(): bool
39    {
40        if (isset($this['data']) && isset($this['data']['locations'])) {
41            foreach ($this['data']['locations'] as $provider) {
42                if (
43                    (!isset($provider['appointment']['external']) || !$provider['appointment']['external'])
44                    && isset($provider['appointment']['allowed']) && $provider['appointment']['allowed']
45                ) {
46                    return true;
47                }
48            }
49        }
50        return false;
51    }
52
53    public function getSource(): mixed
54    {
55        return $this->toProperty()->source->get();
56    }
57
58    public function getGroup(): mixed
59    {
60        return $this->toProperty()->group->get();
61    }
62
63    public function getLink(): mixed
64    {
65        return $this->toProperty()->link->get();
66    }
67
68    public function getName(): mixed
69    {
70        return $this->toProperty()->name->get();
71    }
72
73    public function getAdditionalData(): mixed
74    {
75        return $this->toProperty()->data->get();
76    }
77
78    public function getParentId(): mixed
79    {
80        return $this->toProperty()->parent_id->get();
81    }
82
83    public function getRootParentId(): string
84    {
85        $rootParentId = $this->toProperty()->root_parent_id->get();
86        if ($rootParentId !== null && $rootParentId !== '') {
87            return (string) $rootParentId;
88        }
89
90        return (string) $this->getId();
91    }
92
93    public function getVariantId(): mixed
94    {
95        return $this->toProperty()->variant_id->get();
96    }
97
98    public function __toString()
99    {
100        return $this->getName();
101    }
102}