Lines 32.50% 26 / 80
Methods 23.52% 4 / 17
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 containsLocation 100.00% 8 / 8 100.00% 1 / 1 3
 hasLocation 0.00% 0 / 6 0.00% 0 / 1 12
 hasAppointments 100.00% 8 / 8 100.00% 1 / 1 6
 isResponsibleForAll 0.00% 0 / 1 0.00% 0 / 1 2
 isLocale 100.00% 2 / 2 100.00% 1 / 1 1
 getLocations 0.00% 0 / 4 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] getId 0.00% 0 / 3 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] getName 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsdldb\Entity\Base] getPath 0.00% 0 / 3 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] hasValidOffset 100.00% 4 / 4 100.00% 1 / 1 4
 [BO\Zmsdldb\Entity\Base] getLocale 0.00% 0 / 4 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] getLink 0.00% 0 / 3 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] getType 0.00% 0 / 3 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Base] subcount 0.00% 0 / 3 0.00% 0 / 1 12
 [BO\Zmsdldb\Entity\Base] __set 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsdldb\Entity\Base] offsetSet 40.00% 4 / 10 0.00% 0 / 1 7.46
 [BO\Zmsdldb\Entity\Base] doubleUnterlineToArray 0.00% 0 / 16 0.00% 0 / 1 56
14class Service extends Base
15{
16    /**
17     * Checks, if it contains _all_ locations
18     * Necessary, cause service A might be in location C but not location D,
19     * but service B is in location C and D. On partial check, service a
20     * would be valid for location D.
21     *
22     * @return Bool
23     */
24    public function containsLocation(string|null $location_csv)
25    {
26        $service = $this->getArrayCopy();
27        $locationcompare = explode(',', (string) $location_csv);
28        $locationsfound = array();
29        foreach ($service['locations'] as $locationinfo) {
30            $location_id = $locationinfo['location'];
31            if (in_array($location_id, $locationcompare)) {
32                $locationsfound[$location_id] = $location_id;
33            }
34        }
35        return count($locationcompare) == count($locationsfound);
36    }
37
38    /**
39     * @psalm-api
40     */
41    public function hasLocation(mixed $location_csv): bool
42    {
43        $service = $this->getArrayCopy();
44        $locationcompare = explode(',', (string) $location_csv);
45        foreach ($service['locations'] as $locationinfo) {
46            if (in_array($locationinfo['location'], $locationcompare)) {
47                return true;
48            }
49        }
50        return false;
51    }
52
53    /**
54     * @psalm-api
55     */
56    public function hasAppointments(bool $external = false): bool
57    {
58        foreach ($this['locations'] as $location) {
59            if (isset($location['appointment']['allowed'])) {
60                if ($location['appointment']['allowed']) {
61                    if ($external) {
62                        return true;
63                    } elseif ($location['appointment']['external'] === false) {
64                        return true;
65                    }
66                }
67            }
68        }
69        return false;
70    }
71
72
73    /** @psalm-api */
74    public function isResponsibleForAll(): mixed
75    {
76        return $this['responsibility_all'];
77    }
78
79    /**
80     * @return Bool
81     */
82    public function isLocale(string $locale)
83    {
84        $service = $this->getArrayCopy();
85        return $service['meta']['locale'] == $locale;
86    }
87
88    /**
89     * @psalm-api
90     */
91    public function getLocations(): array
92    {
93        $locations = [];
94        foreach ($this['locations'] as $location) {
95            $locations[$location['location']] = $location;
96        }
97        return $locations;
98    }
99}

Inherited from BO\Zmsdldb\Entity\Base

19    public function getId(): mixed
20    {
21        if (!$this->offsetExists('id')) {
22            return false;
23        }
24        return $this['id'];
25    }
31    public function getName(): mixed
32    {
33        return $this['name'];
34    }
41    public function getPath(): mixed
42    {
43        if (!$this->offsetExists('path')) {
44            return false;
45        }
46        return $this['path'];
47    }
49    public static function hasValidOffset(mixed $item, string $index): bool
50    {
51        return (
52            (is_object($item) && $item->offsetExists($index)) ||
53            (is_array($item) && array_key_exists($index, $item))
54        );
55    }
58    public function getLocale(): mixed
59    {
60        $meta = $this['meta'];
61        if (false === static::hasValidOffset($meta, 'locale')) {
62            return false;
63        }
64        return $this['meta']['locale'];
65    }
68    public function getLink(): mixed
69    {
70        if (!$this->offsetExists('link')) {
71            return false;
72        }
73        return $this['link'];
74    }
76    public function getType(): mixed
77    {
78        if (!$this->offsetExists('type')) {
79            return false;
80        }
81        return $this['type'];
82    }
84    protected static function subcount(mixed $countable): int|null
85    {
86        if (is_array($countable) || $countable instanceof \Countable) {
87            return count($countable);
88        }
89        return null;
90    }
92    public function __set(string $name, mixed $value)
93    {
94        $this->offsetSet($name, $value);
95    }
98    public function offsetSet($index, $value): void
99    {
100        if ('data_json' == $index) {
101            $value = json_decode($value, true);
102            $this->exchangeArray($value);
103        } else {
104            /** @psalm-suppress RiskyTruthyFalsyComparison */
105            if (stripos($index, '_json')) {
106                $value = json_decode($value, true);
107                $index = str_replace('_json', '', $index);
108            }
109            /** @psalm-suppress RiskyTruthyFalsyComparison */
110            if (stripos($index, '__')) {
111                static::doubleUnterlineToArray($this, $index, $value);
112                return;
113            }
114
115            parent::offsetSet($index, $value);
116        }
117    }
123    public static function doubleUnterlineToArray(&$array, string $key, mixed $value): mixed
124    {
125        if ($key === '') {
126            return $array = $value;
127        }
128        $keys = explode('__', $key);
129
130        $numKeys = count($keys);
131        while ($numKeys > 1) {
132            $key = array_shift($keys);
133            $numKeys = count($keys);
134            if ($key === null) {
135                break;
136            }
137            if (! isset($array[$key]) || ! is_array($array[$key])) {
138                $array[$key] = [];
139            }
140
141            $array = &$array[$key];
142        }
143
144        $lastKey = array_shift($keys);
145        if ($lastKey !== null) {
146            $array[$lastKey] = $value;
147        }
148
149        return $array;
150    }