Removing   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
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 52
loc 52
ccs 24
cts 24
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 15 15 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\Module\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\module\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 4
    public function execute(InputInterface $input, OutputInterface $output)
23
    {
24 4
        $moduleName = $input->getArgument('name');
25 4
        if(!$this->getService('module_manager')->has($moduleName)){
26 1
            $output->writeln(sprintf('<error>Error: no module "%s" found</error>', $moduleName));
27 1
            return ITask::BLOCKING_ERROR_CODE;
28
        }
29
30 3
        $module = $this->getService('module_manager')->get($moduleName);
31 3
        if($this->confirmRemove($input, $output, $module->getPackage())){
32 2
            $this->getService('module_procedure')->setOutput($output);
33 2
            $this->getService('module_procedure')->remove($module);
34 2
        }
35 3
        return ITask::NO_ERROR_CODE;
36 4
    }
37
38
    /**
39
     * @param InputInterface $input
40
     * @param OutputInterface $output
41
     * @param string $modulePackage
42
     * @return bool
43
     */
44 3
    private function confirmRemove(InputInterface $input, OutputInterface $output, $modulePackage)
45
    {
46 3
        return $this->getService('helper_set')->get('question')->ask(
47 3
            $input,
48 3
            $output,
49 3
            $this->buildQuestion($modulePackage)
50 3
        );
51
    }
52
53
    /**
54
     * @param string $modulePackage
55
     * @return ConfirmationQuestion
56
     */
57 3
    private function buildQuestion($modulePackage)
58
    {
59 3
        return new ConfirmationQuestion(
60 3
            sprintf(
61 3
                '<question>Do you want to remove the module "%s"</question>[y]',
62
                $modulePackage
63 3
            )
64 3
        );
65
    }
66
}
67