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 |
||
32 | class PatchCommand extends AbstractCommand |
||
33 | { |
||
34 | /** |
||
35 | * Configure command |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | protected function configure() |
||
46 | |||
47 | /** |
||
48 | * Execute command |
||
49 | * |
||
50 | * @param InputInterface $input |
||
51 | * @param OutputInterface $output |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | protected function execute(InputInterface $input, OutputInterface $output) |
||
86 | } |
||
87 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.