Lines
72.97%
54 / 74
Methods
56.25%
9 / 16
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| parseData | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 3 | ||
| fetchList | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 3 | ||
| fetchFromCsv | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | ||
| readSearchResultList | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 1 | ||
| fetchListByOffice | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 2 | ||
| [BO\Zmsdldb\File\Base] __construct | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsdldb\File\Base] readDataFile | 91.66% | 11 / 12 | 0.00% | 0 / 1 | 5.01 | ||
| [BO\Zmsdldb\File\Base] getDataAsArray | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| [BO\Zmsdldb\File\Base] getHash | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| [BO\Zmsdldb\File\Base] getData | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | ||
| [BO\Zmsdldb\File\Base] loadData | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\File\Base] getItemList | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsdldb\File\Base] setItemList | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | ||
| [BO\Zmsdldb\File\Base] fetchId | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| [BO\Zmsdldb\File\Base] setAccessInstance | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [BO\Zmsdldb\File\Base] access | 66.66% | 2 / 3 | 0.00% | 0 / 1 | 2.15 | ||
| 18 | class Location extends Base | |
| 19 | { | |
| 20 | /** | |
| 21 | * @return Collection | |
| 22 | */ | |
| 23 | #[\Override] | |
| 24 | protected function parseData(mixed $data) | |
| 25 | { | |
| 26 | $itemList = new Collection(); | |
| 27 | foreach ($data['data'] as $item) { | |
| 28 | $location = new Entity($item); | |
| 29 | if ($location->isLocale($this->locale)) { | |
| 30 | $itemList[$item['id']] = $location; | |
| 31 | } | |
| 32 | } | |
| 33 | return $itemList; | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * | |
| 38 | * @return Collection | |
| 39 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) | |
| 40 | */ | |
| 41 | public function fetchList(bool|string $service_csv = false, bool $mixLanguages = false) | |
| 42 | { | |
| 43 | $locationlist = $this->getItemList(); | |
| 44 | if (is_string($service_csv) && $service_csv !== '') { | |
| 45 | $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($service_csv) { | |
| 46 | $location = new Entity($item); | |
| 47 | return $location->containsService($service_csv); | |
| 48 | })); | |
| 49 | } | |
| 50 | return $locationlist; | |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * | |
| 55 | * @return Collection | |
| 56 | * @param bool $mixLanguages unused in file backend, kept for MySQL override compatibility | |
| 57 | * @psalm-api | |
| 58 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) | |
| 59 | */ | |
| 60 | public function fetchFromCsv(mixed $location_csv, bool $mixLanguages = false) | |
| 61 | { | |
| 62 | $locationlist = new Collection(); | |
| 63 | foreach (explode(',', $location_csv) as $location_id) { | |
| 64 | $location = $this->fetchId($location_id); | |
| 65 | if ($location && $location->isLocale($this->locale)) { | |
| 66 | $locationlist[$location_id] = $location; | |
| 67 | } | |
| 68 | } | |
| 69 | return $locationlist; | |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * | |
| 74 | * @return \BO\Zmsdldb\Collection\Authorities | |
| 75 | * @psalm-api | |
| 76 | */ | |
| 77 | public function readSearchResultList(mixed $query, string $service_csv = '') | |
| 78 | { | |
| 79 | $locationlist = $this->fetchList($service_csv); | |
| 80 | $locationlist = new Collection(array_filter((array) $locationlist, function ($item) use ($query) { | |
| 81 | return false !== strpos($item['name'], $query); | |
| 82 | })); | |
| 83 | return $this->access() | |
| 84 | ->fromAuthority() | |
| 85 | ->fromLocationResults($locationlist); | |
| 86 | } | |
| 87 | ||
| 88 | /** @psalm-api */ | |
| 89 | public function fetchListByOffice(mixed $office): mixed | |
| 90 | { | |
| 91 | return $this->access()->fromAuthority() | |
| 92 | ->readListByOfficePath($office) | |
| 93 | ->removeEmptyAuthorities() | |
| 94 | ->sortByName(); | |
| 95 | } | |
| 96 | } |
Inherited from BO\Zmsdldb\File\Base
| 49 | public function __construct(mixed $dataFile, string $locale = "de") | |
| 50 | { | |
| 51 | $this->dataFile = $dataFile; | |
| 52 | $this->locale = $locale; | |
| 53 | } |
| 55 | public function readDataFile(): mixed | |
| 56 | { | |
| 57 | if (empty($this->data)) { | |
| 58 | $jsonFile = $this->dataFile; | |
| 59 | if (!is_readable($jsonFile)) { | |
| 60 | throw new Exception("Cannot read $jsonFile"); | |
| 61 | } | |
| 62 | $json = file_get_contents($jsonFile); | |
| 63 | if ($json === false) { | |
| 64 | throw new Exception("Cannot read $jsonFile"); | |
| 65 | } | |
| 66 | $data = json_decode($json, true); | |
| 67 | if (!$data) { | |
| 68 | throw new Exception("Could not decide $jsonFile"); | |
| 69 | } | |
| 70 | $this->data = $data; | |
| 71 | } | |
| 72 | return $this->data; | |
| 73 | } |
| 76 | public function getDataAsArray(): mixed | |
| 77 | { | |
| 78 | try { | |
| 79 | $data = $this->readDataFile(); | |
| 80 | ||
| 81 | return $data['data']; | |
| 82 | } catch (\Exception $e) { | |
| 83 | throw $e; | |
| 84 | } | |
| 85 | } |
| 88 | public function getHash(): mixed | |
| 89 | { | |
| 90 | try { | |
| 91 | $data = $this->readDataFile(); | |
| 92 | ||
| 93 | return $data['hash']; | |
| 94 | } catch (\Exception $e) { | |
| 95 | throw $e; | |
| 96 | } | |
| 97 | } |
| 100 | public function getData(): mixed | |
| 101 | { | |
| 102 | try { | |
| 103 | $data = $this->readDataFile(); | |
| 104 | ||
| 105 | return $data; | |
| 106 | } catch (\Exception $e) { | |
| 107 | throw $e; | |
| 108 | } | |
| 109 | } |
| 114 | public function loadData() | |
| 115 | { | |
| 116 | try { | |
| 117 | $data = $this->readDataFile(); | |
| 118 | $this->itemList = $this->parseData($data); | |
| 119 | } catch (\Exception $e) { | |
| 120 | throw $e; | |
| 121 | } | |
| 122 | } |
| 127 | public function getItemList() | |
| 128 | { | |
| 129 | if (null === $this->itemList) { | |
| 130 | $this->loadData(); | |
| 131 | } | |
| 132 | return $this->itemList; | |
| 133 | } |
| 135 | protected function setItemList(\BO\Zmsdldb\Collection\Base $list): static | |
| 136 | { | |
| 137 | /** @var TCollection $list */ | |
| 138 | $this->itemList = $list; | |
| 139 | return $this; | |
| 140 | } |
| 145 | public function fetchId(string $itemId) | |
| 146 | { | |
| 147 | $itemList = $this->getItemList(); | |
| 148 | ||
| 149 | if (! $itemId || !$itemList->offsetExists($itemId)) { | |
| 150 | return false; | |
| 151 | } | |
| 152 | ||
| 153 | /** @var TEntity $item */ | |
| 154 | $item = $itemList[$itemId]; | |
| 155 | return $item; | |
| 156 | } |
| 158 | public function setAccessInstance(\BO\Zmsdldb\AbstractAccess $accessInstance): void | |
| 159 | { | |
| 160 | $this->accessInstance = $accessInstance; | |
| 161 | } |
| 163 | public function access(): \BO\Zmsdldb\AbstractAccess | |
| 164 | { | |
| 165 | if (!$this->accessInstance instanceof \BO\Zmsdldb\AbstractAccess) { | |
| 166 | throw new Exception('Access instance is not initialized'); | |
| 167 | } | |
| 168 | return $this->accessInstance; | |
| 169 | } |