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 |
||
9 | abstract class AbstractBaseCommand extends Command implements ContainerAwareInterface |
||
10 | { |
||
11 | use ContainerAwareTrait; |
||
12 | |||
13 | protected $input; |
||
14 | protected $output; |
||
15 | protected $dialog; |
||
16 | |||
17 | /** |
||
18 | * @param string $option |
||
19 | * |
||
20 | * @return string |
||
21 | */ |
||
22 | View Code Duplication | protected function getOptionOrAsk($option, $question, $default = null) |
|
33 | |||
34 | /** |
||
35 | * @param string $option |
||
36 | */ |
||
37 | protected function getOptionOrSelect($option, $question, array $choices, $default = null) |
||
53 | |||
54 | /** |
||
55 | * @param string $option |
||
56 | */ |
||
57 | protected function getOptionOrAskConfirmation($option, $question, $default = null) |
||
72 | |||
73 | /** |
||
74 | * @param string $option |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | View Code Duplication | protected function getOptionOrAskAndValidate($option, $question, \Closure $callback, $default = null) |
|
94 | } |
||
95 |
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.