Lines 29.34% 27 / 92
Methods 33.33% 5 / 15
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 fetchList 0.00% 0 / 13 0.00% 0 / 1 6
 fetchPath 0.00% 0 / 11 0.00% 0 / 1 20
 fetchId 0.00% 0 / 11 0.00% 0 / 1 20
 readSearchResultList 0.00% 0 / 14 0.00% 0 / 1 6
 [BO\Zmsdldb\File\Topic] parseData 100.00% 4 / 4 100.00% 1 / 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] 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
15class Topic extends Base
16{
17    #[\Override]
18    public function fetchList(): Collection
19    {
20        try {
21            $sqlArgs = [$this->locale];
22            $sql = 'SELECT data_json FROM topic WHERE locale = ?';
23
24            $topiclist = new Collection();
25
26            $stm = $this->access()->prepare($sql);
27            $stm->execute($sqlArgs);
28            $stm->fetchAll(\PDO::FETCH_FUNC, function (?string $data_json) use ($topiclist): void {
29                $topic = new Entity();
30                $topic->offsetSet('data_json', $data_json);
31
32                $topiclist[$topic['id']] = $topic;
33            });
34
35            return $topiclist;
36        } catch (\Exception $e) {
37            throw $e;
38        }
39    }
40
41    /**
42     *
43     * @return Entity|false
44     */
45    #[\Override]
46    public function fetchPath(mixed $topic_path): Entity|false
47    {
48        try {
49            $sqlArgs = [$this->locale, $topic_path];
50            $sql = 'SELECT data_json FROM topic WHERE locale = ? AND path = ?';
51
52            $stm = $this->access()->prepare($sql);
53            $stm->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, Entity::class);
54            $stm->execute($sqlArgs);
55
56            if ($stm->rowCount() === 0) {
57                return false;
58            }
59            $topic = $stm->fetch();
60            return $topic instanceof Entity ? $topic : false;
61        } catch (\Exception $e) {
62            throw $e;
63        }
64    }
65
66    /**
67     *
68     * @return Entity|false
69     */
70    #[\Override]
71    public function fetchId(mixed $itemId): Entity|false
72    {
73        try {
74            $sqlArgs = [$this->locale, (int)$itemId];
75            $sql = 'SELECT data_json FROM topic WHERE locale = ? AND id = ?';
76
77            $stm = $this->access()->prepare($sql);
78            $stm->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, Entity::class);
79            $stm->execute($sqlArgs);
80
81            if ($stm->rowCount() === 0) {
82                return false;
83            }
84            $topic = $stm->fetch();
85            return $topic instanceof Entity ? $topic : false;
86        } catch (\Exception $e) {
87            throw $e;
88        }
89    }
90
91    #[\Override]
92    public function readSearchResultList(mixed $querystring): Collection
93    {
94        try {
95            #$querystring = '+' . implode(' +', explode(' ', $querystring));
96            $sqlArgs = [$this->locale, $this->locale, $querystring];
97            $sql = "SELECT t.data_json 
98            FROM search AS se
99            LEFT JOIN topic AS t ON t.id = se.object_id AND t.locale = ?
100            WHERE 
101                se.locale = ? AND MATCH (search_value) AGAINST (? IN BOOLEAN MODE)
102                AND (search_type IN ('name', 'keywords', 'titles')) AND entity_type='topic'
103             GROUP BY se.object_id
104            ";
105            /*
106            if (!empty($service_csv)) {
107                $ids = explode(',', $service_csv);
108                $qm = array_fill(0, count($ids), '?');
109                $sql .= ' AND se.object_id IN (' . implode(', ', $qm) . ')';
110                array_push($sqlArgs, ...$ids);
111            }*/
112            #print_r($sql);exit;
113
114            $topiclist = new Collection();
115
116            $stm = $this->access()->prepare($sql);
117            $stm->execute($sqlArgs);
118            $stm->fetchAll(\PDO::FETCH_FUNC, function (?string $data_json) use ($topiclist): void {
119                $topic = new Entity();
120                $topic->offsetSet('data_json', $data_json);
121
122                $topiclist[$topic['id']] = $topic;
123            });
124
125            return $topiclist;
126        } catch (\Exception $e) {
127            throw $e;
128        }
129    }
130}

Inherited from BO\Zmsdldb\File\Topic

24    protected function parseData(mixed $data)
25    {
26        $itemList = new Collection();
27        foreach ($data['data'] as $item) {
28            $itemList[$item['id']] = new Entity($item);
29        }
30        return $itemList;
31    }

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    }
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    }