Lines 33.89% 20 / 59
Methods 21.42% 3 / 14
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 parseData 0.00% 0 / 1 0.00% 0 / 1 2
 getItemList 0.00% 0 / 17 0.00% 0 / 1 90
 fetchList 0.00% 0 / 1 0.00% 0 / 1 2
 fetchId 0.00% 0 / 3 0.00% 0 / 1 6
 fetchPath 0.00% 0 / 1 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] setItemList 0.00% 0 / 2 0.00% 0 / 1 2
 [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
18class Office extends Base
19{
20    protected static Collection|array $officeList = [];
21
22    #[\Override]
23    protected function parseData(mixed $data): Collection
24    {
25        return $this->getItemList();
26    }
27
28    #[\Override]
29    public function getItemList(): Collection
30    {
31        try {
32            if (!static::$officeList instanceof Collection) {
33                $officeListJson = $this->access()->fromSetting()->fetchName('office');
34                $officeList = is_string($officeListJson) ? json_decode($officeListJson, true) : [];
35                if (!is_array($officeList)) {
36                    $officeList = [];
37                }
38
39                static::$officeList = new Collection();
40                foreach ($officeList as $item) {
41                    if (!is_array($item)) {
42                        continue;
43                    }
44                    $office = new Entity($item);
45                    if (isset($item['path'])) {
46                        static::$officeList[$item['path']] = $office;
47                    }
48                    if (isset($item['plural'])) {
49                        static::$officeList[$item['plural']] = $office;
50                    }
51                }
52                #echo '<pre>' . htmlspecialchars(print_r((static::$officeList),1)) . '</pre>';exit;
53            }
54            return static::$officeList;
55        } catch (\Exception $e) {
56            throw $e;
57        }
58    }
59
60    #[\Override]
61    public function fetchList(): Collection
62    {
63        return $this->getItemList();
64    }
65
66    #[\Override]
67    public function fetchId(mixed $itemId): Entity|false
68    {
69        $list = $this->fetchList();
70        $office = $list[$itemId] ?? false;
71        return $office instanceof Entity ? $office : false;
72    }
73
74    #[\Override]
75    public function fetchPath(mixed $itemId): Entity|false
76    {
77        return $this->fetchId($itemId);
78    }
79}

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    }
135    protected function setItemList(\BO\Zmsdldb\Collection\Base $list): static
136    {
137        /** @var TCollection $list */
138        $this->itemList = $list;
139        return $this;
140    }
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    }