RemoveCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 8
Ratio 57.14 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 14
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
3
namespace Geekish\Crap\Command;
4
5
use Composer\Command\RemoveCommand as ComposerRemoveCommand;
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 RemoveCommand
12
 * @package Geekish\Crap\Command
13
 */
14 View Code Duplication
final class RemoveCommand 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('remove');
22
        $this->setDescription('Gets package name and version by alias, calls `composer remove`');
23
        $this->addArgument('aliases', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package aliases');
24
25
        $command = new ComposerRemoveCommand;
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'), true);
39
40
        $options = $this->getOptions($input, $output->isDecorated());
41
        $helper = $this->getHelper('process');
42
        $process = $this->createProcess('remove', $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