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 |
||
18 | class Controller extends \yii\console\Controller |
||
19 | { |
||
20 | /** |
||
21 | * Link to module. |
||
22 | * |
||
23 | * @var \herroffizier\yii2dumpling\Module |
||
24 | */ |
||
25 | public $module; |
||
26 | |||
27 | /** |
||
28 | * Dump file name. |
||
29 | * |
||
30 | * @var string|null |
||
31 | */ |
||
32 | public $file; |
||
33 | |||
34 | /** |
||
35 | * Database component. |
||
36 | * |
||
37 | * @var string|null |
||
38 | */ |
||
39 | public $db; |
||
40 | |||
41 | /** |
||
42 | * @param string $actionID |
||
43 | * |
||
44 | * @return array |
||
|
|||
45 | * @codeCoverageIgnore |
||
46 | */ |
||
47 | public function options($actionID) |
||
51 | |||
52 | protected function getDumpFile() |
||
56 | |||
57 | protected function getDbComponent() |
||
61 | |||
62 | /** |
||
63 | * Dump database. |
||
64 | */ |
||
65 | View Code Duplication | public function actionDump() |
|
78 | |||
79 | /** |
||
80 | * Restore database. |
||
81 | */ |
||
82 | View Code Duplication | public function actionRestore() |
|
95 | } |
||
96 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.