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 |
||
19 | class CornifyCommand extends BaseCommand |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Configure the cornify command |
||
24 | * |
||
25 | * @return void |
||
26 | */ |
||
27 | protected function configure() |
||
36 | |||
37 | /** |
||
38 | * @param InputInterface $input |
||
39 | * @param OutputInterface $output |
||
40 | * @return int|null|void |
||
41 | */ |
||
42 | public function execute(InputInterface $input, OutputInterface $output) |
||
63 | |||
64 | /** |
||
65 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
66 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
67 | * @param $helper |
||
68 | * @param $indexName |
||
69 | * @return bool |
||
70 | */ |
||
71 | View Code Duplication | private function createConfiguration(InputInterface $input, OutputInterface $output, $helper, $indexName) |
|
81 | |||
82 | /** |
||
83 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
84 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
85 | * @param $helper |
||
86 | * @return bool |
||
87 | */ |
||
88 | View Code Duplication | private function compareConfiguration(InputInterface $input, OutputInterface $output, $helper, $indexName) |
|
99 | } |
||
100 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.