Completed
Push — master ( eb931e...d2a66f )
by Hannah
11:28
created

UnaliasCommand::execute()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 13

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 3
eloc 13
nc 3
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::REQUIRED, "Package alias");
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 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
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...
36
    {
37
        $alias = $input->getArgument("alias");
38
39
        if ($this->helper->hasAlias($alias)) {
40
            if ($input->getOption("dry-run") !== true) {
41
                $this->helper->unsetAlias($alias);
42
            }
43
44
            $output->writeln(sprintf(
45
                "<success>Alias `%s` successfully removed.</success>",
46
                $alias
47
            ));
48
49
            return 0;
50
        }
51
52
        $output->writeln(sprintf(
53
            "<comment>Alias `%s` does not exist.</comment>",
54
            $alias
55
        ));
56
57
        return 1;
58
    }
59
}
60