Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
87.50% |
28 / 32 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
SysCheckReportOutput | |
87.50% |
28 / 32 |
|
66.67% |
2 / 3 |
5.05 | |
0.00% |
0 / 1 |
asString | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
generate | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
generateCsvReportData | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | class SysCheckReportOutput extends Report { |
6 | |
7 | public function asString(): string { |
8 | return match ($this->format) { |
9 | ReportFormat::CSV => $this->csvReportData, |
10 | ReportFormat::JSON => json_encode($this->reportData) |
11 | }; |
12 | } |
13 | |
14 | public function generate(bool $useNewVersion = false): bool { |
15 | $this->useNewVersion = $useNewVersion; |
16 | $sysChecksFolder = new SysChecksFolder($this->workspaceId); |
17 | $systemChecks = $sysChecksFolder->collectSysCheckReports($this->dataIds); |
18 | |
19 | if (empty($systemChecks)) { |
20 | return false; |
21 | |
22 | } else { |
23 | $this->reportData = array_map( |
24 | function (SysCheckReportFile $report) { |
25 | return $report->getReport(); |
26 | }, |
27 | $systemChecks |
28 | ); |
29 | |
30 | if ($this->format == ReportFormat::CSV) { |
31 | $flatReports = array_map( |
32 | function (SysCheckReportFile $report) { |
33 | return $report->getFlatReport(); |
34 | }, |
35 | $systemChecks |
36 | ); |
37 | $this->csvReportData = $this->generateCsvReportData($flatReports); |
38 | } |
39 | } |
40 | return true; |
41 | |
42 | } |
43 | |
44 | private function generateCsvReportData(array $flatReports): string { |
45 | return self::BOM . |
46 | CSV::build( |
47 | $flatReports, |
48 | [], |
49 | self::DELIMITER, |
50 | self::ENCLOSURE, |
51 | self::LINE_ENDING |
52 | ); |
53 | } |
54 | } |