Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
36 / 36 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ReportsCommand | |
100.00% |
36 / 36 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| configure | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| generateFrontpage | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| renderTemplate | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of fast-forward/dev-tools. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\DevTools\Command; |
| 20 | |
| 21 | use Symfony\Component\Console\Input\InputInterface; |
| 22 | use Symfony\Component\Console\Output\OutputInterface; |
| 23 | |
| 24 | use function Safe\ob_start; |
| 25 | use function Safe\ob_get_clean; |
| 26 | |
| 27 | /** |
| 28 | * Coordinates the generation of Fast Forward documentation frontpage and related reports. |
| 29 | * This class MUST NOT be overridden and SHALL securely combine docs and testing commands. |
| 30 | */ |
| 31 | final class ReportsCommand extends AbstractCommand |
| 32 | { |
| 33 | /** |
| 34 | * Configures the metadata for the reports generation command. |
| 35 | * |
| 36 | * The method MUST identify the command correctly and describe its intent broadly. |
| 37 | * |
| 38 | * @return void |
| 39 | */ |
| 40 | protected function configure(): void |
| 41 | { |
| 42 | $this |
| 43 | ->setName('reports') |
| 44 | ->setDescription('Generates the frontpage for Fast Forward documentation.') |
| 45 | ->setHelp( |
| 46 | 'This command generates the frontpage for Fast Forward documentation, including links to API documentation and test reports.' |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Executes the generation logic for diverse reports. |
| 52 | * |
| 53 | * The method MUST run the underlying `docs` and `tests` commands. It SHALL process |
| 54 | * and generate the frontpage output file successfully. |
| 55 | * |
| 56 | * @param InputInterface $input the structured inputs holding specific arguments |
| 57 | * @param OutputInterface $output the designated output interface |
| 58 | * |
| 59 | * @return int the integer outcome from the base process execution |
| 60 | */ |
| 61 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 62 | { |
| 63 | $output->writeln('<info>Generating frontpage for Fast Forward documentation...</info>'); |
| 64 | |
| 65 | $docsPath = $this->getAbsolutePath('public/docs'); |
| 66 | $coveragePath = $this->getAbsolutePath('public/coverage'); |
| 67 | |
| 68 | $output->writeln('<info>Generating API documentation on path: ' . $docsPath . '</info>'); |
| 69 | $this->runCommand('docs', [ |
| 70 | '--target' => $docsPath, |
| 71 | ], $output); |
| 72 | |
| 73 | $output->writeln('<info>Generating test coverage report on path: ' . $coveragePath . '</info>'); |
| 74 | $this->runCommand('tests', [ |
| 75 | '--coverage' => $coveragePath, |
| 76 | ], $output); |
| 77 | |
| 78 | $this->generateFrontpage(); |
| 79 | |
| 80 | $output->writeln('<info>Frontpage generation completed!</info>'); |
| 81 | |
| 82 | return self::SUCCESS; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Generates the compiled documentation frontpage correctly. |
| 87 | * |
| 88 | * This method MUST collect the configured render template and write it persistently |
| 89 | * to the `public/index.html` directory. |
| 90 | * |
| 91 | * @return void |
| 92 | */ |
| 93 | private function generateFrontpage(): void |
| 94 | { |
| 95 | $html = $this->renderTemplate( |
| 96 | $this->getProjectDescription(), |
| 97 | [ |
| 98 | 'Documentation' => './docs/index.html', |
| 99 | 'Testdox Report' => './coverage/testdox.html', |
| 100 | 'Test Coverage Report' => './coverage/index.html', |
| 101 | ] |
| 102 | ); |
| 103 | |
| 104 | $this->filesystem->dumpFile($this->getAbsolutePath('public/index.html'), $html); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Constructs string variations defining standard components by linking to predefined resources. |
| 109 | * |
| 110 | * The method MUST extract variables correctly and stream the content safely. |
| 111 | * It SHALL strictly return the interpreted string structure. |
| 112 | * |
| 113 | * @param string $title the main title intended for the index interface |
| 114 | * @param array<string, string> $links the associative array representing link titles and their URIs |
| 115 | * |
| 116 | * @return string the evaluated and parsed HTML content |
| 117 | */ |
| 118 | private function renderTemplate(string $title, array $links): string |
| 119 | { |
| 120 | ob_start(); |
| 121 | extract([ |
| 122 | 'title' => $title, |
| 123 | 'links' => $links, |
| 124 | ]); |
| 125 | include $this->getConfigFile('resources/index.php'); |
| 126 | |
| 127 | return ob_get_clean(); |
| 128 | } |
| 129 | } |