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 |
||
14 | class MigrationMakeCommand extends GeneratorCommand |
||
15 | { |
||
16 | use ModuleCommandTrait; |
||
17 | |||
18 | /** |
||
19 | * The console command name. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $name = 'module:make-migration'; |
||
24 | |||
25 | /** |
||
26 | * The console command description. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $description = 'Create a new migration for the specified module.'; |
||
31 | |||
32 | /** |
||
33 | * Get the console command arguments. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | 128 | protected function getArguments() |
|
44 | |||
45 | /** |
||
46 | * Get the console command options. |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 128 | View Code Duplication | protected function getOptions() |
51 | { |
||
52 | return [ |
||
53 | 128 | ['fields', null, InputOption::VALUE_OPTIONAL, 'The specified fields table.', null], |
|
54 | ['plain', null, InputOption::VALUE_NONE, 'Create plain migration.'], |
||
55 | ]; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get schema parser. |
||
60 | * |
||
61 | * @return SchemaParser |
||
62 | */ |
||
63 | 10 | public function getSchemaParser() |
|
67 | |||
68 | /** |
||
69 | * @throws \InvalidArgumentException |
||
70 | * |
||
71 | * @return mixed |
||
72 | */ |
||
73 | 11 | protected function getTemplateContents() |
|
109 | |||
110 | /** |
||
111 | * @return mixed |
||
112 | */ |
||
113 | 11 | protected function getDestinationFilePath() |
|
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | 11 | private function getFileName() |
|
129 | |||
130 | /** |
||
131 | * @return array|string |
||
132 | */ |
||
133 | 11 | private function getSchemaName() |
|
137 | |||
138 | /** |
||
139 | * @return string |
||
140 | */ |
||
141 | 11 | private function getClassName() |
|
145 | |||
146 | 11 | public function getClass() |
|
150 | |||
151 | /** |
||
152 | * Run the command. |
||
153 | */ |
||
154 | 11 | public function handle() : int |
|
166 | } |
||
167 |
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.