Lines
62.06%
18 / 29
Functions and Methods
50.00%
3 / 6
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Service | 62.06% | 18 / 29 | 50.00% | 3 / 6 | 29.97 | 0.00% | 0 / 1 | |||
| 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 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package Zmsdldb | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsdldb\Entity; | |
| 9 | ||
| 10 | /** | |
| 11 | * Helper for service export | |
| 12 | * | |
| 13 | */ | |
| 14 | class 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 | } |