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 |
||
13 | class CommandAssistant |
||
14 | { |
||
15 | /** |
||
16 | * @var InputInterface |
||
17 | */ |
||
18 | private $input; |
||
19 | |||
20 | /** |
||
21 | * @var OutputInterface |
||
22 | */ |
||
23 | private $output; |
||
24 | |||
25 | /** |
||
26 | * @var QuestionHelper |
||
27 | */ |
||
28 | private $questionHelper; |
||
29 | |||
30 | /** |
||
31 | * @var Kernel |
||
32 | */ |
||
33 | private $kernel; |
||
34 | |||
35 | /** |
||
36 | * @param $input InputInterface |
||
37 | */ |
||
38 | public function setInput(InputInterface $input) |
||
42 | |||
43 | /** |
||
44 | * @return OutputInterface |
||
45 | */ |
||
46 | public function getOutput() |
||
50 | |||
51 | /** |
||
52 | * @param $output OutputInterface |
||
53 | */ |
||
54 | public function setOutput(OutputInterface $output) |
||
58 | |||
59 | /** |
||
60 | * @param $questionHelper QuestionHelper |
||
61 | */ |
||
62 | public function setQuestionHelper(QuestionHelper $questionHelper) |
||
66 | |||
67 | /** |
||
68 | * @return Kernel |
||
69 | */ |
||
70 | public function getKernel() |
||
74 | |||
75 | /** |
||
76 | * @param $kernel Kernel |
||
77 | */ |
||
78 | public function setKernel(Kernel $kernel) |
||
82 | |||
83 | public function writeSection($text, $style = 'bg=blue;fg=white') |
||
87 | |||
88 | /** |
||
89 | * @return Questionhelper |
||
|
|||
90 | */ |
||
91 | private function getQuestionHelper() |
||
95 | |||
96 | public function writeLine($text, $type = OutputInterface::OUTPUT_NORMAL) |
||
100 | |||
101 | public function write( |
||
108 | |||
109 | View Code Duplication | public function writeError($message, $exit = false) |
|
121 | |||
122 | View Code Duplication | public function askAndValidate( |
|
141 | |||
142 | public function askConfirmation( |
||
162 | |||
163 | View Code Duplication | public function ask($question, $default = null, array $autoComplete = null) |
|
176 | |||
177 | public function askSelect( |
||
214 | |||
215 | public function setOption($name, $value) |
||
219 | |||
220 | public function hasOption($name) |
||
224 | |||
225 | public function getOption($name) |
||
229 | |||
230 | public function isInteractive() |
||
234 | |||
235 | public function getOptionOrDefault($option, $default = null) |
||
241 | } |
||
242 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.