Lines
100.00%
6 / 6
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| create | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 4 | ||
| getExportTimestamp | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| 33 | class Export | |
| 34 | { | |
| 35 | protected Faq $faq; | |
| 36 | ||
| 37 | protected Category $category; | |
| 38 | ||
| 39 | protected Configuration $config; | |
| 40 | ||
| 41 | /** | |
| 42 | * Factory. | |
| 43 | * @throws Exception | |
| 44 | */ | |
| 45 | public static function create( | |
| 46 | Faq $faq, | |
| 47 | Category $category, | |
| 48 | Configuration $configuration, | |
| 49 | string $mode = 'pdf', | |
| 50 | ): Pdf|Json { | |
| 51 | return match ($mode) { | |
| 52 | 'json' => new Json($faq, $category, $configuration), | |
| 53 | 'pdf' => new Pdf($faq, $category, $configuration), | |
| 54 | default => throw new Exception(message: 'Export not implemented!'), | |
| 55 | }; | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Returns the timestamp of the export. | |
| 60 | */ | |
| 61 | public static function getExportTimestamp(): string | |
| 62 | { | |
| 63 | $requestTime = Request::createFromGlobals()->server->get(key: 'REQUEST_TIME'); | |
| 64 | ||
| 65 | return date(format: 'Y-m-d-H-i-s', timestamp: is_numeric($requestTime) ? (int) $requestTime : time()); | |
| 66 | } | |
| 67 | } |