Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.92% covered (warning)
76.92%
40 / 52
35.71% covered (danger)
35.71%
5 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
FileAccess
76.92% covered (warning)
76.92%
40 / 52
35.71% covered (danger)
35.71%
5 / 14
24.92
0.00% covered (danger)
0.00%
0 / 1
 __construct
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
6.29
 loadFromPath
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
2.00
 loadLocationsFromPathByLocale
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadServicesFromPathByLocale
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadTopicsFromPathByLocale
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadAuthoritiesFromPathByLocale
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadSettingsFromPath
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadLocations
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 loadServices
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 loadTopics
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 loadSettings
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 loadAuthorities
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 fetchTopicServicesList
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 fetchLocationListByOffice
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @package 115Mandant
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsdldb;
9
10/**
11 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
12 */
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        $locationJson = null,
22        $serviceJson = null,
23        $topicsJson = null,
24        $authoritiesJson = null,
25        $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($path, $locale): void
71    {
72        $this->loadLocations($path . DIRECTORY_SEPARATOR . 'locations_' . $locale . '.json', $locale);
73    }
74
75    /**
76     * @psalm-api
77     */
78    public function loadServicesFromPathByLocale($path, $locale): void
79    {
80        $this->loadServices($path . DIRECTORY_SEPARATOR . 'services_' . $locale . '.json', $locale);
81    }
82
83    /**
84     * @psalm-api
85     */
86    public function loadTopicsFromPathByLocale($path, $locale): void
87    {
88        $this->loadTopics($path . DIRECTORY_SEPARATOR . 'topic_' . $locale . '.json', $locale);
89    }
90
91    /**
92     * @psalm-api
93     */
94    public function loadAuthoritiesFromPathByLocale($path, $locale): void
95    {
96        $this->loadAuthorities($path . DIRECTORY_SEPARATOR . 'authority_' . $locale . '.json', $locale);
97    }
98
99    /**
100     * @psalm-api
101     */
102    public function loadSettingsFromPath($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($topic_path)
174    {
175        trigger_error("Deprecated function fetchTopicServicesList, use fromService()->fetchTopic()");
176        return $this->fromService()->fetchTopicPath($topic_path);
177    }
178
179    /**
180     *
181     * @todo will not work in every edge case, cause authority export does not contain officeinformations
182     * @todo returns Collection\Authorities and not locations
183     * @return \BO\Zmsdldb\Collection\Authorities
184     * @psalm-api
185     */
186    public function fetchLocationListByOffice($officepath = false)
187    {
188        trigger_error("Deprecated function fetchLocationListByOffice, use fromAuthority()->fetchOffice()");
189        return $this->fromAuthority()->fetchOffice($officepath);
190    }
191}