Lines 81.10% 103 / 127
Methods 51.85% 14 / 27
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __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
 [BO\Zmsdldb\AbstractAccess] addAccessInstanceLocale 0.00% 0 / 2 0.00% 0 / 1 6
 [BO\Zmsdldb\AbstractAccess] getInstanceCompatibilities 100.00% 9 / 9 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] __call 96.77% 30 / 31 0.00% 0 / 1 9
 [BO\Zmsdldb\AbstractAccess] getInstanceOnName 100.00% 4 / 4 100.00% 1 / 1 3
 [BO\Zmsdldb\AbstractAccess] from 46.15% 6 / 13 0.00% 0 / 1 11.62
 [BO\Zmsdldb\AbstractAccess] fromAuthority 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromBorough 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromLink 0.00% 0 / 2 0.00% 0 / 1 2
 [BO\Zmsdldb\AbstractAccess] fromLocation 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromOffice 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromService 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromSetting 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsdldb\AbstractAccess] fromTopic 100.00% 2 / 2 100.00% 1 / 1 1
13class 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}

Inherited from BO\Zmsdldb\AbstractAccess

54    public function addAccessInstanceLocale(string $locale = 'de'): void
55    {
56        if (!isset($this->accessInstance[$locale])) {
57            $this->accessInstance[$locale] = static::$accessInstanceTypes;
58        }
59    }
62    private function getInstanceCompatibilities(): mixed
63    {
64        $accessInstance = $this->accessInstance['de'];
65        $accessInstance['Authorities'] = $accessInstance['Authority'];
66        $accessInstance['Boroughs'] = $accessInstance['Borough'];
67        $accessInstance['Offices'] = $accessInstance['Office'];
68        $accessInstance['Settings'] = $accessInstance['Setting'];
69        $accessInstance['Topics'] = $accessInstance['Topic'];
70        $accessInstance['Locations'] = $accessInstance['Location'];
71        $accessInstance['Services'] = $accessInstance['Service'];
72        return $accessInstance;
73    }
80    public function __call(string $functionName, array $functionArguments)
81    {
82        if (self::$showDeprecated) {
83            trigger_error("Deprecated access function: $functionName");
84        }
85        $actionType = 'none';
86        $instanceName = 'Missing';
87        $actionName = 'Nothing';
88        if (0 === strpos($functionName, 'fetch')) {
89            $actionType = 'fetch';
90            /** @var string|null $instanceName */
91            $instanceName = $this->getInstanceOnName($functionName, 5);
92            $actionName = substr($functionName, 5 + strlen($instanceName ?? ''));
93            if (! $actionName) {
94                $actionName = 'Id';
95            }
96        } elseif (0 === strpos($functionName, 'search')) {
97            $actionType = 'search';
98            /** @var string|null $instanceName */
99            $instanceName = $this->getInstanceOnName($functionName, 6);
100            $actionName = substr($functionName, 6 + strlen($instanceName ?? ''));
101            if (! $actionName) {
102                $actionType = "read";
103                $actionName = 'SearchResultList';
104            }
105        }
106        $accessInstance = $this->getInstanceCompatibilities();
107        /** @psalm-suppress RiskyTruthyFalsyComparison */
108        if (
109            $instanceName
110            && $instanceName != 'Missing'
111            && method_exists($accessInstance[$instanceName], $actionType . $actionName)
112        ) {
113            $accessInstance[$instanceName]->setAccessInstance($this);
114            return call_user_func_array(array(
115                $accessInstance[$instanceName],
116                $actionType . $actionName
117            ), $functionArguments);
118        }
119        $classname = get_class($this);
120        throw new Exception(
121            "Unknown access function or instance: $classname::$functionName ($instanceName::$actionType$actionName)"
122        );
123    }
128    protected function getInstanceOnName(mixed $name, int $position = 0)
129    {
130        foreach (array_keys($this->getInstanceCompatibilities()) as $instanceName) {
131            if ($position === strpos($name, $instanceName)) {
132                return $instanceName;
133            }
134        }
135        return null;
136    }
138    protected function from(string $instanceName, string $locale = 'de'): File\Base
139    {
140        if (array_key_exists($instanceName, $this->accessInstance[$locale])) {
141            $instance = $this->accessInstance[$locale][$instanceName];
142            if ($instance instanceof \BO\Zmsdldb\File\Base) {
143                return $instance;
144            }
145            if (null === $instance) {
146                throw new Exception("Instance for accessing $instanceName ($locale) is not initialized");
147            }
148            throw new Exception("Instance for accessing $instanceName failed");
149        }
150        if (class_exists('\App', false) && isset(\App::$log)) {
151            \App::$log->error('DLDB access locale missing', [
152                'instance' => $instanceName,
153                'locale' => $locale,
154            ]);
155        }
156        throw new Exception("Locale for accessing $instanceName does not exists");
157    }
159    public function fromAuthority(string $locale = 'de'): File\Authority
160    {
161        /** @var File\Authority $instance */
162        $instance = $this->from('Authority', $locale);
163        return $instance;
164    }
166    public function fromBorough(): File\Borough
167    {
168        /** @var File\Borough $instance */
169        $instance = $this->from('Borough');
170        return $instance;
171    }
174    public function fromLink(string $locale = 'de'): File\Link
175    {
176        /** @var File\Link $instance */
177        $instance = $this->from('Link', $locale);
178        return $instance;
179    }
181    public function fromLocation(string $locale = 'de'): File\Location
182    {
183        /** @var File\Location $instance */
184        $instance = $this->from('Location', $locale);
185        return $instance;
186    }
188    public function fromOffice(): File\Office
189    {
190        /** @var File\Office $instance */
191        $instance = $this->from('Office');
192        return $instance;
193    }
195    public function fromService(string $locale = 'de'): File\Service
196    {
197        /** @var File\Service $instance */
198        $instance = $this->from('Service', $locale);
199        return $instance;
200    }
202    public function fromSetting(): File\Setting
203    {
204        /** @var File\Setting $instance */
205        $instance = $this->from('Setting');
206        return $instance;
207    }
209    public function fromTopic(string $locale = 'de'): File\Topic
210    {
211        /** @var File\Topic $instance */
212        $instance = $this->from('Topic', $locale);
213        return $instance;
214    }