Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WikiCommand | |
100.00% |
34 / 34 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| configure | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
3 | |||
| 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\Input\InputOption; |
| 23 | use Symfony\Component\Console\Output\OutputInterface; |
| 24 | use Symfony\Component\Process\Process; |
| 25 | |
| 26 | /** |
| 27 | * Handles the generation of API documentation for the project. |
| 28 | * This class MUST NOT be extended and SHALL utilize phpDocumentor to accomplish its task. |
| 29 | */ |
| 30 | final class WikiCommand extends AbstractCommand |
| 31 | { |
| 32 | /** |
| 33 | * Configures the command instance. |
| 34 | * |
| 35 | * The method MUST set up the name and description. It MAY accept an optional `--target` option |
| 36 | * pointing to an alternative configuration target path. |
| 37 | * |
| 38 | * @return void |
| 39 | */ |
| 40 | protected function configure(): void |
| 41 | { |
| 42 | $this |
| 43 | ->setName('wiki') |
| 44 | ->setDescription('Generates API documentation in Markdown format.') |
| 45 | ->setHelp('This command generates API documentation in Markdown format using phpDocumentor.') |
| 46 | ->addOption( |
| 47 | name: 'target', |
| 48 | shortcut: 't', |
| 49 | mode: InputOption::VALUE_OPTIONAL, |
| 50 | description: 'Path to the output directory for the generated Markdown documentation.', |
| 51 | default: '.github/wiki' |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Executes the generation of the documentation files in Markdown format. |
| 57 | * |
| 58 | * This method MUST compile arguments based on PSR-4 namespaces to feed into phpDocumentor. |
| 59 | * It SHOULD provide feedback on generation progress, and SHALL return `self::SUCCESS` on success. |
| 60 | * |
| 61 | * @param InputInterface $input the input details for the command |
| 62 | * @param OutputInterface $output the output mechanism for logging |
| 63 | * |
| 64 | * @return int the final execution status code |
| 65 | */ |
| 66 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 67 | { |
| 68 | $output->writeln('<info>Generating API documentation...</info>'); |
| 69 | |
| 70 | $arguments = [ |
| 71 | $this->getAbsolutePath('vendor/bin/phpdoc'), |
| 72 | '--cache-folder', |
| 73 | $this->getCurrentWorkingDirectory() . '/tmp/cache/phpdoc', |
| 74 | '--visibility=public,protected', |
| 75 | '--title=' . $this->getProjectDescription(), |
| 76 | ]; |
| 77 | |
| 78 | $psr4Namespaces = $this->getPsr4Namespaces(); |
| 79 | |
| 80 | foreach ($psr4Namespaces as $path) { |
| 81 | $arguments[] = '--directory'; |
| 82 | $arguments[] = $path; |
| 83 | } |
| 84 | |
| 85 | if ($defaultPackageName = array_key_first($psr4Namespaces)) { |
| 86 | $arguments[] = '--defaultpackagename'; |
| 87 | $arguments[] = $defaultPackageName; |
| 88 | } |
| 89 | |
| 90 | $command = new Process([ |
| 91 | ...$arguments, |
| 92 | '--target', |
| 93 | $this->getAbsolutePath($input->getOption('target')), |
| 94 | '--template', |
| 95 | 'vendor/saggre/phpdocumentor-markdown/themes/markdown', |
| 96 | ]); |
| 97 | |
| 98 | return parent::runProcess($command, $output); |
| 99 | } |
| 100 | } |