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 | 1 | public function setOutput(OutputInterface $output) |
|
55 | { |
||
56 | 1 | $this->output = $output; |
|
57 | 1 | } |
|
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 | 1 | public function writeLine($text, $type = OutputInterface::OUTPUT_NORMAL) |
|
97 | { |
||
98 | 1 | $this->output->writeln($text, $type); |
|
99 | 1 | } |
|
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( |
||
143 | $question, |
||
163 | |||
164 | View Code Duplication | public function ask($question, $default = null, array $autoComplete = null) |
|
165 | { |
||
166 | $askQuestion = new Question( |
||
167 | $this->questionHelper->getQuestion($question, $default), |
||
168 | $default |
||
169 | ); |
||
170 | $askQuestion->setAutocompleterValues($autoComplete); |
||
171 | |||
172 | return $this->getQuestionHelper()->ask( |
||
173 | $this->input, |
||
174 | $this->output, |
||
175 | $askQuestion |
||
176 | ); |
||
177 | } |
||
178 | |||
179 | public function askSelect( |
||
216 | |||
217 | public function setOption($name, $value) |
||
221 | |||
222 | public function hasOption($name) |
||
226 | |||
227 | public function getOption($name) |
||
231 | |||
232 | public function isInteractive() |
||
236 | |||
237 | public function getOptionOrDefault($option, $default = null) |
||
243 | } |
||
244 |
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.