Removing   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 3
dl 50
loc 50
ccs 22
cts 22
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 13 13 3
A confirmRemove() 8 8 1
A buildQuestion() 9 9 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
namespace Samurai\Alias\Task;
3
4
use Samurai\Task\ITask;
5
use Samurai\Task\Task;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Question\ConfirmationQuestion;
9
10
/**
11
 * Class Removing
12
 * @package Samurai\Alias\Task
13
 * @author Raphaël Lefebvre <[email protected]>
14
 */
15 View Code Duplication
class Removing extends Task
16
{
17
    /**
18
     * @param InputInterface $input
19
     * @param OutputInterface $output
20
     * @return bool
21
     */
22 5
    public function execute(InputInterface $input, OutputInterface $output)
23
    {
24 5
        $aliasName = $input->getArgument('name');
25 5
        if(!$this->getService('alias_manager')->hasLocal($aliasName)){
26 1
            $output->writeln(sprintf('<error>Error: no alias "%s" found</error>', $aliasName));
27 1
            return ITask::BLOCKING_ERROR_CODE;
28
        }
29 4
        $alias = $this->getService('alias_manager')->get($aliasName);
30 4
        if($this->confirmRemove($input, $output, $alias->getPackage())){
31 2
            $this->getService('alias_manager')->remove($aliasName);
32 2
        }
33 4
        return ITask::NO_ERROR_CODE;
34
    }
35
36
    /**
37
     * @param InputInterface $input
38
     * @param OutputInterface $output
39
     * @param string $aliasPackage
40
     * @return bool
41
     */
42 4
    private function confirmRemove(InputInterface $input, OutputInterface $output, $aliasPackage)
43
    {
44 4
        return $this->getService('helper_set')->get('question')->ask(
45 4
            $input,
46 4
            $output,
47 4
            $this->buildQuestion($aliasPackage)
48 4
        );
49
    }
50
51
    /**
52
     * @param string $aliasPackage
53
     * @return ConfirmationQuestion
54
     */
55 4
    private function buildQuestion($aliasPackage)
56
    {
57 4
        return new ConfirmationQuestion(
58 4
            sprintf(
59 4
                '<question>Do you want to remove the bootstrap "%s"</question>[y]',
60
                $aliasPackage
61 4
            )
62 4
        );
63
    }
64
}
65