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 |
||
12 | class ControllerMakeCommand extends GeneratorCommand |
||
13 | { |
||
14 | use ModuleCommandTrait; |
||
15 | |||
16 | /** |
||
17 | * The name of argument being used. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $argumentName = 'controller'; |
||
22 | |||
23 | /** |
||
24 | * The console command name. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $name = 'module:make-controller'; |
||
29 | |||
30 | /** |
||
31 | * The console command description. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $description = 'Generate new restful controller for the specified module.'; |
||
36 | |||
37 | /** |
||
38 | * Get controller name. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | 111 | public function getDestinationFilePath() |
|
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | 111 | protected function getTemplateContents() |
|
71 | |||
72 | /** |
||
73 | * Get the console command arguments. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | 120 | protected function getArguments() |
|
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | 120 | View Code Duplication | protected function getOptions() |
95 | |||
96 | /** |
||
97 | * @return array|string |
||
98 | */ |
||
99 | 111 | protected function getControllerName() |
|
109 | |||
110 | /** |
||
111 | * @return array|string |
||
112 | */ |
||
113 | 111 | private function getControllerNameWithoutNamespace() |
|
117 | |||
118 | 111 | public function getDefaultNamespace() : string |
|
124 | |||
125 | /** |
||
126 | * Get the stub file name based on the options |
||
127 | * @return string |
||
128 | */ |
||
129 | 111 | private function getStubName() |
|
141 | } |
||
142 |
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.