Lines 33.89% 40 / 118
Methods 22.22% 4 / 18
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 [BO\Zmsdldb\Entity\Location] containsService 90.00% 9 / 10 0.00% 0 / 1 6.04
 [BO\Zmsdldb\Entity\Location] isLocale 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\Entity\Location] getServiceInfo 0.00% 0 / 4 0.00% 0 / 1 12
 [BO\Zmsdldb\Entity\Location] getServiceInfoList 100.00% 10 / 10 100.00% 1 / 1 4
 [BO\Zmsdldb\Entity\Location] hasAppointments 100.00% 11 / 11 100.00% 1 / 1 9
 [BO\Zmsdldb\Entity\Location] getAppointmentForService 0.00% 0 / 5 0.00% 0 / 1 6
 [BO\Zmsdldb\Entity\Location] getGeoJson 0.00% 0 / 25 0.00% 0 / 1 2
 [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
15class Location extends Base
16{
17}

Inherited from BO\Zmsdldb\Entity\Location

19    public function containsService(mixed $service_csv)
20    {
21        if (!is_string($service_csv) && !is_int($service_csv) && !is_float($service_csv)) {
22            return false;
23        }
24        $location = $this->getArrayCopy();
25        $servicecompare = explode(',', (string) $service_csv);
26        $servicecount = array();
27        foreach ($location['services'] as $serviceinfo) {
28            $service_id = $serviceinfo['service'];
29            if (in_array($service_id, $servicecompare)) {
30                $servicecount[$service_id] = $service_id;
31            }
32        }
33        return count($servicecount) == count($servicecompare);
34    }
39    public function isLocale(string $locale)
40    {
41        $location = $this->getArrayCopy();
42        return $location['meta']['locale'] == $locale;
43    }
51    public function getServiceInfo(mixed $service_id)
52    {
53        foreach ($this['services'] as $service) {
54            if ($service['service'] == $service_id) {
55                return $service;
56            }
57        }
58        return false;
59    }
66    public function getServiceInfoList($serviceCsv = null)
67    {
68        if (null === $serviceCsv) {
69            return $this['services'];
70        }
71        $location = $this->getArrayCopy();
72        $servicecompare = explode(',', (string) $serviceCsv);
73
74        $serviceList = array();
75        foreach ($location['services'] as $serviceinfo) {
76            $service_id = $serviceinfo['service'];
77            if (in_array($service_id, $servicecompare)) {
78                $serviceList[$service_id] = $serviceinfo;
79            }
80        }
81        return $serviceList;
82    }
93    public function hasAppointments($serviceCsv = null, $external = false)
94    {
95        $serviceList = $this->getServiceInfoList($serviceCsv);
96        $servicecount = array();
97        foreach ($serviceList as $serviceinfo) {
98            if (
99                true === static::hasValidOffset($serviceinfo, 'appointment')
100                && $serviceinfo['appointment']['allowed']
101                && ($external || $serviceinfo['appointment']['external'] === false)
102            ) {
103                $service_id = $serviceinfo['service'];
104                $servicecount[$service_id] = $service_id;
105            }
106        }
107        if (null === $serviceCsv) {
108            return count($servicecount) ? true : false;
109        } else {
110            return count($serviceList) > 0 && count($servicecount) == count($serviceList);
111        }
112    }
118    public function getAppointmentForService(mixed $service_id, bool $external = false): mixed
119    {
120        $serviceList = $this->getServiceInfoList($service_id);
121
122        if (!empty($serviceList)) {
123            $service = end($serviceList);
124            return $service['appointment'];
125        }
126        return false;
127    }
135    public function getGeoJson()
136    {
137        return [
138            'type' => 'Feature',
139            'id' => $this['id'],
140            'properties' => [
141                'name' => $this['name'],
142                'description' => '<div>'
143                    . ($this['authority']['name'] ?? $this['authority_name'] ?? '')
144                    . '</div><p>'
145                    . $this['address']['street']
146                    . ' '
147                    . $this['address']['house_number']
148                    . ', '
149                    . $this['address']['postal_code']
150                    . ' '
151                    . $this['address']['city']
152                    . '<br /><a href="'
153                    . ($this['meta']['url'] ?? $this['url'])
154                    . '" class="gmap-marker-link">Zum Standort</a>',
155                'categoryIdentifier' => $this['category']['identifier'],
156            ],
157            'geometry' => [
158                'type' => 'Point',
159                'coordinates' => [$this['geo']['lon'], $this['geo']['lat']],
160            ]
161        ];
162    }

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    }