UnaliasCommand::execute()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 2
1
<?php
2
3
namespace Geekish\Crap\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class UnaliasCommand
12
 * @package Geekish\Crap\Command
13
 */
14
final class UnaliasCommand extends BaseCommand
15
{
16
    /**
17
     * @inheritDoc
18
     */
19 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method 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...
20
    {
21
        $this->setName('unalias');
22
        $this->setDescription('Unset an existing crap alias.');
23
        $this->addArgument('alias', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package alias(es)');
24
        $this->addOption(
25
            'dry-run',
26
            null,
27
            InputOption::VALUE_NONE,
28
            'Run command without writing to your `crap.json`, useful for testing.'
29
        );
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $aliases = $input->getArgument('alias');
38
39
        foreach ($aliases as $alias) {
40
            if (!$this->helper->hasAlias($alias)) {
41
                $output->writeln(sprintf(
42
                    '<comment>Alias `%s` does not exist. Skipping.</comment>',
43
                    $alias
44
                ));
45
                continue;
46
            }
47
48
            if ($input->getOption('dry-run') !== true) {
49
                $this->helper->unsetAlias($alias);
50
            }
51
52
            $output->writeln(sprintf(
53
                '<success>Alias `%s` successfully removed.</success>',
54
                $alias
55
            ));
56
        }
57
58
        return 0;
59
    }
60
}
61