RemoveCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 81.08 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 2
cbo 7
dl 30
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 12 12 2
A execute() 8 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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