Lines 100.00% 19 / 19
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fetchAllReportData 100.00% 18 / 18 100.00% 1 / 1 5
25readonly class ReportRepository
26{
27    public function __construct(
28        private Configuration $configuration,
29    ) {
30    }
31
32    /**
33     * Fetches all FAQ data with related information for reporting.
34     *
35     * @return array<int, \stdClass>
36     */
37    public function fetchAllReportData(): array
38    {
39        $query = sprintf(
40            '
41            SELECT
42                fd.id AS id,
43                fd.lang AS lang,
44                fcr.category_id AS category_id,
45                c.name as category_name,
46                c.parent_id as parent_id,
47                fd.sticky AS sticky,
48                fd.thema AS question,
49                fd.author AS original_author,
50                fd.updated AS updated,
51                fv.visits AS visits,
52                u.display_name AS last_author
53            FROM
54                %sfaqdata fd
55            LEFT JOIN
56                %sfaqcategoryrelations fcr
57            ON
58                (fd.id = fcr.record_id AND fd.lang = fcr.record_lang)
59            LEFT JOIN
60                %sfaqvisits fv
61            ON
62                (fd.id = fv.id AND fd.lang = fv.lang)
63            LEFT JOIN
64                %sfaqchanges as fc
65            ON
66                (fd.id = fc.id AND fd.lang = fc.lang)
67            LEFT JOIN
68                %sfaquserdata as u
69            ON
70                (u.user_id = fc.usr)
71            LEFT JOIN
72                %sfaqcategories as c
73            ON
74                (c.id = fcr.category_id AND c.lang = fcr.record_lang)
75            ORDER BY
76                fd.id
77            ASC',
78            Database::getTablePrefix(),
79            Database::getTablePrefix(),
80            Database::getTablePrefix(),
81            Database::getTablePrefix(),
82            Database::getTablePrefix(),
83            Database::getTablePrefix(),
84        );
85
86        $result = $this->configuration->getDb()->query($query);
87
88        $rows = [];
89        while (true) {
90            $row = $this->configuration->getDb()->fetchObject($result);
91            if ($row === false || $row === null || $row === []) {
92                break;
93            }
94
95            $rows[] = $row;
96        }
97
98        return $rows;
99    }
100}