Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| RuntimeCommand | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| configure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Console\Command; |
| 21 | |
| 22 | use FastForward\DevTools\Console\Input\HasJsonOption; |
| 23 | use FastForward\DevTools\Path\DevToolsPathResolver; |
| 24 | use FastForward\DevTools\Path\WorkingProjectPathResolver; |
| 25 | use FastForward\DevTools\SelfUpdate\VersionCheckerInterface; |
| 26 | use Symfony\Component\Console\Attribute\AsCommand; |
| 27 | use Symfony\Component\Console\Command\Command; |
| 28 | use Symfony\Component\Console\Input\InputInterface; |
| 29 | use Symfony\Component\Console\Output\OutputInterface; |
| 30 | |
| 31 | use function Safe\json_encode; |
| 32 | |
| 33 | /** |
| 34 | * Exposes runtime paths without relying on an executor's private cache layout. |
| 35 | * |
| 36 | * The command MUST emit one JSON object without changing the working project. |
| 37 | */ |
| 38 | #[AsCommand(name: 'runtime', description: 'Prints the active DevTools runtime as JSON.', aliases: [])] |
| 39 | class RuntimeCommand extends Command |
| 40 | { |
| 41 | use HasJsonOption; |
| 42 | |
| 43 | /** |
| 44 | * @param VersionCheckerInterface $versionChecker resolves the active package version |
| 45 | */ |
| 46 | public function __construct( |
| 47 | private VersionCheckerInterface $versionChecker |
| 48 | ) { |
| 49 | parent::__construct(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return void |
| 54 | */ |
| 55 | protected function configure(): void |
| 56 | { |
| 57 | $this->addJsonOption(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param InputInterface $input |
| 62 | * @param OutputInterface $output |
| 63 | * |
| 64 | * @return int |
| 65 | */ |
| 66 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 67 | { |
| 68 | $output->writeln(json_encode([ |
| 69 | 'binary' => DevToolsPathResolver::getBinaryPath(), |
| 70 | 'autoload' => DevToolsPathResolver::getRuntimeAutoloadPath(), |
| 71 | 'package_root' => DevToolsPathResolver::getPackagePath(), |
| 72 | 'project_root' => WorkingProjectPathResolver::getProjectPath(), |
| 73 | 'version' => $this->versionChecker->getCurrentVersion(), |
| 74 | ], \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR)); |
| 75 | |
| 76 | return self::SUCCESS; |
| 77 | } |
| 78 | } |