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 FactoryMakeCommand extends GeneratorCommand |
||
| 13 | { |
||
| 14 | use ModuleCommandTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The name of argument name. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $argumentName = 'name'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The console command name. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $name = 'module:make-factory'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The console command description. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $description = 'Create a new model factory for the specified module.'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get the console command arguments. |
||
| 39 | * |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | 130 | protected function getArguments() |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @return mixed |
||
| 52 | */ |
||
| 53 | 1 | View Code Duplication | protected function getTemplateContents() |
| 64 | |||
| 65 | /** |
||
| 66 | * @return mixed |
||
| 67 | */ |
||
| 68 | 1 | protected function getDestinationFilePath() |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Get class name. |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | 1 | public function getClass() |
|
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * Get model class name. |
||
| 95 | * |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | 1 | public function getModelClass() |
|
| 121 | |||
| 122 | |||
| 123 | /** |
||
| 124 | * Get model class name. |
||
| 125 | * |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | 1 | public function getModelName() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | 1 | private function getFileName() |
|
| 140 | |||
| 141 | |||
| 142 | /** |
||
| 143 | * Get the console command options. |
||
| 144 | * |
||
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | 130 | protected function getOptions() |
|
| 153 | |||
| 154 | 1 | public function getDefaultNamespace() : string |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Get class namespace. |
||
| 163 | * |
||
| 164 | * @param \Nwidart\Modules\Module $module |
||
| 165 | * |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | 1 | public function getClassNamespace($module) |
|
| 180 | } |
||
| 181 |
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.