Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.54% |
3 / 26 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PrefixComposerAutoloadFilesCommand | |
11.54% |
3 / 26 |
|
25.00% |
1 / 4 |
22.31 | |
0.00% |
0 / 1 |
| configure | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| loadProjectComposerPackage | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| loadConfigFromComposerJson | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * |
| 5 | * @package brianhenryie/strauss |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\Strauss\Console\Commands; |
| 9 | |
| 10 | use BrianHenryIE\Strauss\Composer\Extra\StraussConfig; |
| 11 | use BrianHenryIE\Strauss\Composer\ProjectComposerPackage; |
| 12 | use BrianHenryIE\Strauss\Pipeline\Autoload\VendorComposerAutoload; |
| 13 | use BrianHenryIE\Strauss\Pipeline\Prefixer; |
| 14 | use Composer\Factory; |
| 15 | use Composer\Util\Platform; |
| 16 | use Exception; |
| 17 | use Symfony\Component\Console\Command\Command; |
| 18 | use Symfony\Component\Console\Input\InputInterface; |
| 19 | use Symfony\Component\Console\Output\OutputInterface; |
| 20 | |
| 21 | class PrefixComposerAutoloadFilesCommand extends AbstractRenamespacerCommand |
| 22 | { |
| 23 | /** |
| 24 | * Set name and description, add CLI arguments, call parent class to add dry-run, verbosity options. |
| 25 | * |
| 26 | * @used-by \Symfony\Component\Console\Command\Command::__construct |
| 27 | * @override {@see \Symfony\Component\Console\Command\Command::configure()} empty method. |
| 28 | * |
| 29 | * @return void |
| 30 | */ |
| 31 | protected function configure() |
| 32 | { |
| 33 | $this->setName('prefix-vendor-autoload'); |
| 34 | $this->setDescription("Prefixes Composer's autoload_real.php etc."); |
| 35 | |
| 36 | parent::configure(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param InputInterface $input |
| 41 | * @param OutputInterface $output |
| 42 | * |
| 43 | * @see Command::execute() |
| 44 | * |
| 45 | */ |
| 46 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 47 | { |
| 48 | try { |
| 49 | // Pipeline |
| 50 | $this->loadProjectComposerPackage(); |
| 51 | $this->loadConfigFromComposerJson(); |
| 52 | |
| 53 | parent::execute($input, $output); |
| 54 | |
| 55 | // TODO: check for `--no-dev` somewhere. |
| 56 | |
| 57 | $replacer = new Prefixer( |
| 58 | $this->config, |
| 59 | $this->filesystem, |
| 60 | $this->logger |
| 61 | ); |
| 62 | |
| 63 | $replacer->prefixComposerAutoloadFiles($this->config->getAbsoluteTargetDirectory()); |
| 64 | } catch (Exception $e) { |
| 65 | $this->logger->error($e->getMessage()); |
| 66 | |
| 67 | return Command::FAILURE; |
| 68 | } |
| 69 | |
| 70 | return Command::SUCCESS; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * 1. Load the composer.json. |
| 76 | * |
| 77 | * @throws Exception |
| 78 | */ |
| 79 | protected function loadProjectComposerPackage(): void |
| 80 | { |
| 81 | $this->logger->notice('Loading package...'); |
| 82 | |
| 83 | $this->projectComposerPackage = new ProjectComposerPackage( |
| 84 | $this->filesystem->makeAbsolute( |
| 85 | $this->workingDir . '/' . Factory::getComposerFile() |
| 86 | ) |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | protected function loadConfigFromComposerJson(): void |
| 91 | { |
| 92 | $this->logger->notice('Loading composer.json config...'); |
| 93 | |
| 94 | $this->config = $this->projectComposerPackage->getStraussConfig(); |
| 95 | $config = new StraussConfig(); |
| 96 | $config->setProjectAbsolutePath(Platform::getcwd()); |
| 97 | } |
| 98 | } |