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 |
||
21 | abstract class ImportCommandAbstract extends Command |
||
22 | { |
||
23 | /** |
||
24 | * @var Finder |
||
25 | */ |
||
26 | protected $finder; |
||
27 | |||
28 | /** |
||
29 | * @param Finder $finder finder instance |
||
30 | */ |
||
31 | 6 | public function __construct( |
|
37 | |||
38 | /** |
||
39 | * Executes the current command. |
||
40 | * |
||
41 | * @param InputInterface $input User input on console |
||
42 | * @param OutputInterface $output Output of the command |
||
43 | * |
||
44 | * @return integer |
||
45 | */ |
||
46 | 6 | protected function execute(InputInterface $input, OutputInterface $output) |
|
56 | |||
57 | /** |
||
58 | * Returns a Finder according to the input params |
||
59 | * |
||
60 | * @param InputInterface $input User input on console |
||
61 | * |
||
62 | * @return Finder|SplFileInfo[] finder |
||
63 | */ |
||
64 | 6 | protected function getFinder($input) |
|
120 | |||
121 | /** |
||
122 | * the actual command can do his import here.. |
||
123 | * |
||
124 | * @param Finder $finder finder |
||
125 | * @param InputInterface $input input |
||
126 | * @param OutputInterface $output output |
||
127 | * |
||
128 | * @return mixed |
||
129 | */ |
||
130 | abstract protected function doImport(Finder $finder, InputInterface $input, OutputInterface $output); |
||
131 | } |
||
132 |
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.