Lines
76.92%
40 / 52
Functions and Methods
35.71%
5 / 14
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| FileAccess | 76.92% | 40 / 52 | 35.71% | 5 / 14 | 24.92 | 0.00% | 0 / 1 | |||
| __construct | 80.00% | 8 / 10 | 0.00% | 0 / 1 | 6.29 | |||||
| loadFromPath | 91.66% | 11 / 12 | 0.00% | 0 / 1 | 2.00 | |||||
| loadLocationsFromPathByLocale | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| loadServicesFromPathByLocale | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| loadTopicsFromPathByLocale | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| loadAuthoritiesFromPathByLocale | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| loadSettingsFromPath | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| loadLocations | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| loadServices | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| loadTopics | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 1 | |||||
| loadSettings | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 1 | |||||
| loadAuthorities | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| fetchTopicServicesList | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | |||||
| fetchLocationListByOffice | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package 115Mandant | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsdldb; | |
| 9 | ||
| 10 | /** | |
| 11 | * @SuppressWarnings(PHPMD.TooManyPublicMethods) | |
| 12 | */ | |
| 13 | class FileAccess extends AbstractAccess | |
| 14 | { | |
| 15 | /** | |
| 16 | * Parameters for json files are deprecated, try using loadFromPath() instead | |
| 17 | * | |
| 18 | * @return self | |
| 19 | */ | |
| 20 | public function __construct( | |
| 21 | mixed $locationJson = null, | |
| 22 | mixed $serviceJson = null, | |
| 23 | mixed $topicsJson = null, | |
| 24 | mixed $authoritiesJson = null, | |
| 25 | mixed $settingsJson = null | |
| 26 | ) { | |
| 27 | if (null !== $locationJson) { | |
| 28 | $this->loadLocations($locationJson); | |
| 29 | } | |
| 30 | if (null !== $serviceJson) { | |
| 31 | $this->loadServices($serviceJson); | |
| 32 | } | |
| 33 | if (null !== $topicsJson) { | |
| 34 | $this->loadTopics($topicsJson); | |
| 35 | } | |
| 36 | if (null !== $authoritiesJson) { | |
| 37 | $this->loadAuthorities($authoritiesJson); | |
| 38 | } | |
| 39 | if (null !== $settingsJson) { | |
| 40 | $this->loadSettings($settingsJson); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * Parameters for json files are deprecated, try using loadFromPath() instead | |
| 46 | * | |
| 47 | * @return self | |
| 48 | * | |
| 49 | */ | |
| 50 | public function loadFromPath(string $path) | |
| 51 | { | |
| 52 | if (!is_dir($path)) { | |
| 53 | throw new Exception("Could not read directory $path"); | |
| 54 | } | |
| 55 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_de.json', 'de'); | |
| 56 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_de.json', 'en'); | |
| 57 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_de.json', 'de'); | |
| 58 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_en.json', 'en'); | |
| 59 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_de.json', 'de'); | |
| 60 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_en.json', 'en'); | |
| 61 | $this->loadSettings($path . DIRECTORY_SEPARATOR . 'settings.json'); | |
| 62 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_de.json', 'de'); | |
| 63 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_de.json', 'en'); | |
| 64 | return $this; | |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * @psalm-api | |
| 69 | */ | |
| 70 | public function loadLocationsFromPathByLocale(mixed $path, mixed $locale): void | |
| 71 | { | |
| 72 | $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_' . $locale . '.json', $locale); | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * @psalm-api | |
| 77 | */ | |
| 78 | public function loadServicesFromPathByLocale(mixed $path, mixed $locale): void | |
| 79 | { | |
| 80 | $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_' . $locale . '.json', $locale); | |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * @psalm-api | |
| 85 | */ | |
| 86 | public function loadTopicsFromPathByLocale(mixed $path, mixed $locale): void | |
| 87 | { | |
| 88 | $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_' . $locale . '.json', $locale); | |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * @psalm-api | |
| 93 | */ | |
| 94 | public function loadAuthoritiesFromPathByLocale(mixed $path, mixed $locale): void | |
| 95 | { | |
| 96 | $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_' . $locale . '.json', $locale); | |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * @psalm-api | |
| 101 | */ | |
| 102 | public function loadSettingsFromPath(mixed $path): void | |
| 103 | { | |
| 104 | $this->loadSettings($path . DIRECTORY_SEPARATOR . 'settings.json'); | |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * @return self | |
| 109 | * | |
| 110 | */ | |
| 111 | public function loadLocations(string $locationJson, string $locale = 'de') | |
| 112 | { | |
| 113 | $this->accessInstance[$locale]['Location'] = new File\Location($locationJson, $locale); | |
| 114 | $this->accessInstance[$locale]['Location']->setAccessInstance($this); | |
| 115 | return $this; | |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * @return self | |
| 120 | * | |
| 121 | */ | |
| 122 | public function loadServices(string $serviceJson, string $locale = 'de') | |
| 123 | { | |
| 124 | $this->accessInstance[$locale]['Service'] = new File\Service($serviceJson, $locale); | |
| 125 | $this->accessInstance[$locale]['Service']->setAccessInstance($this); | |
| 126 | return $this; | |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * @return self | |
| 131 | * | |
| 132 | */ | |
| 133 | public function loadTopics(string $topicJson, string $locale = 'de') | |
| 134 | { | |
| 135 | $this->accessInstance[$locale]['Topic'] = new File\Topic($topicJson, $locale); | |
| 136 | $this->accessInstance[$locale]['Topic']->setAccessInstance($this); | |
| 137 | $this->accessInstance[$locale]['Link'] = new File\Link($topicJson, $locale); | |
| 138 | $this->accessInstance[$locale]['Link']->setAccessInstance($this); | |
| 139 | return $this; | |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * | |
| 144 | * @return self | |
| 145 | */ | |
| 146 | public function loadSettings(string $settingsJson) | |
| 147 | { | |
| 148 | $this->accessInstance['de']['Setting'] = new File\Setting($settingsJson); | |
| 149 | $this->accessInstance['de']['Setting']->setAccessInstance($this); | |
| 150 | $this->accessInstance['de']['Office'] = new File\Office($settingsJson); | |
| 151 | $this->accessInstance['de']['Office']->setAccessInstance($this); | |
| 152 | $this->accessInstance['de']['Borough'] = new File\Borough($settingsJson); | |
| 153 | $this->accessInstance['de']['Borough']->setAccessInstance($this); | |
| 154 | return $this; | |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * @return self | |
| 159 | * | |
| 160 | */ | |
| 161 | public function loadAuthorities(string $authorityJson, string $locale = 'de') | |
| 162 | { | |
| 163 | $this->accessInstance[$locale]['Authority'] = new File\Authority($authorityJson, $locale); | |
| 164 | $this->accessInstance[$locale]['Authority']->setAccessInstance($this); | |
| 165 | return $this; | |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * | |
| 170 | * @todo refactor: returns services, not topics. | |
| 171 | * @psalm-api | |
| 172 | */ | |
| 173 | public function fetchTopicServicesList(mixed $topic_path): mixed | |
| 174 | { | |
| 175 | trigger_error("Deprecated function fetchTopicServicesList, use fromService()->fetchTopic()"); | |
| 176 | /** @psalm-suppress UndefinedMethod */ | |
| 177 | return $this->fromService()->fetchTopicPath($topic_path); | |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * | |
| 182 | * @todo will not work in every edge case, cause authority export does not contain officeinformations | |
| 183 | * @todo returns Collection\Authorities and not locations | |
| 184 | * @return \BO\Zmsdldb\Collection\Authorities | |
| 185 | * @psalm-api | |
| 186 | */ | |
| 187 | public function fetchLocationListByOffice(string|false $officepath = false) | |
| 188 | { | |
| 189 | trigger_error("Deprecated function fetchLocationListByOffice, use fromAuthority()->fetchOffice()"); | |
| 190 | /** @psalm-suppress UndefinedMethod */ | |
| 191 | return $this->fromAuthority()->fetchOffice($officepath); | |
| 192 | } | |
| 193 | } |