Completed
Push — dev ( a8234e...9312cf )
by Zach
04:40
created

NullCommand   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 13.16 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 10
loc 76
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A addArgument() 0 9 1
A addOption() 0 10 1
A getName() 0 4 1
A getDescription() 0 4 1
A getArguments() 0 4 1
A getOptions() 0 4 1
A __construct() 0 4 1
A setName() 0 4 1
A setDescription() 0 3 1
A addInput() 10 10 2

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 Yarak\Console\Stubs;
4
5
use Yarak\Console\Input\Input;
6
use Symfony\Component\Console\Command\Command;
7
8
class NullCommand extends Command
9
{
10
    protected $name;
11
12
    protected $description;
13
14
    protected $options = [];
15
16
    protected $arguments = [];
17
18
    public function __construct($name = null)
19
    {
20
        $this->name = $name;
21
    }
22
23
    public function setName($name)
24
    {
25
        $this->name = $name;
26
    }
27
28
    public function setDescription($description)
29
    {
30
    }
31
32
    public function addArgument($name, $mode = null, $description = '', $default = null)
33
    {
34
        $this->arguments[] = [
35
            'name'        => $name,
36
            'mode'        => $mode,
37
            'description' => $description,
38
            'default'     => $default,
39
        ];
40
    }
41
42
    public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
43
    {
44
        $this->options[] = [
45
            'name'        => $name,
46
            'shortcut'    => $shortcut,
47
            'mode'        => $mode,
48
            'description' => $description,
49
            'default'     => $default,
50
        ];
51
    }
52
53
    public function getName()
54
    {
55
        return $this->name;
56
    }
57
58
    public function getDescription()
59
    {
60
        return $this->description;
61
    }
62
63
    public function getArguments()
64
    {
65
        return $this->arguments;
66
    }
67
68
    public function getOptions()
69
    {
70
        return $this->options;
71
    }
72
73 View Code Duplication
    public function addInput(Input $input)
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...
74
    {
75
        $reflection = new \ReflectionClass($input);
76
77
        $method = 'add'.$reflection->getShortName();
78
79
        if (method_exists($this, $method)) {
80
            $this->$method(...array_values($input->getAttributes()));
81
        }
82
    }
83
}
84