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 |
||
| 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) |
||
| 41 | |||
| 42 | public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null) |
||
| 52 | |||
| 53 | public function getName() |
||
| 57 | |||
| 58 | public function getDescription() |
||
| 62 | |||
| 63 | public function getArguments() |
||
| 67 | |||
| 68 | public function getOptions() |
||
| 72 | |||
| 73 | View Code Duplication | public function addInput(Input $input) |
|
|
|
|||
| 74 | { |
||
| 75 | $reflection = new \ReflectionClass($input); |
||
| 83 | } |
||
| 84 |
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.