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 MigrationCommand extends GeneratorCommand |
||
14 | { |
||
15 | use ModuleCommandTrait; |
||
16 | |||
17 | /** |
||
18 | * The console command name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name = 'module:make-migration'; |
||
23 | |||
24 | /** |
||
25 | * The console command description. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $description = 'Generate a new migration for the specified module.'; |
||
30 | |||
31 | /** |
||
32 | * Get the console command arguments. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | 16 | protected function getArguments() |
|
43 | |||
44 | /** |
||
45 | * Get the console command options. |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | 16 | protected function getOptions() |
|
56 | |||
57 | /** |
||
58 | * Get schema parser. |
||
59 | * |
||
60 | * @return SchemaParser |
||
61 | */ |
||
62 | 1 | public function getSchemaParser() |
|
66 | |||
67 | /** |
||
68 | * @throws InvalidMigrationNameException |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 1 | protected function getTemplateContents() |
|
106 | |||
107 | /** |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 1 | protected function getDestinationFilePath() |
|
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | 1 | private function getFileName() |
|
126 | |||
127 | /** |
||
128 | * @return array|string |
||
129 | */ |
||
130 | 1 | private function getSchemaName() |
|
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 1 | private function getClassName() |
|
142 | |||
143 | 1 | public function getClass() |
|
147 | |||
148 | /** |
||
149 | * Run the command. |
||
150 | */ |
||
151 | 1 | public function fire() |
|
160 | } |
||
161 |
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.