RequireCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
3
namespace Geekish\Crap\Command;
4
5
use Composer\Command\RequireCommand as ComposerRequireCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class RequireCommand
12
 * @package Geekish\Crap\Command
13
 */
14 View Code Duplication
final class RequireCommand extends BaseComposerCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    protected function configure()
20
    {
21
        $this->setName('require');
22
        $this->setDescription('Gets package name and version by alias, calls `composer require`');
23
        $this->addArgument('aliases', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package aliases');
24
25
        $command = new ComposerRequireCommand;
26
27
        foreach ($command->getDefinition()->getOptions() as $option) {
28
            $this->getDefinition()->addOption($option);
29
        }
30
    }
31
32
    /**
33
     * @inheritDoc
34
     * @codeCoverageIgnore
35
     */
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $packages = $this->helper->parseArguments($input->getArgument('aliases'));
39
40
        $options = $this->getOptions($input, $output->isDecorated());
41
        $helper = $this->getHelper('process');
42
        $process = $this->createProcess('require', $packages, $options);
43
44
        $helper->run($output, $process, 'Command failed.', function ($type, $data) use ($output) {
45
            $output->write($data, false);
46
        });
47
48
        return $process->getExitCode();
49
    }
50
}
51