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 |
||
11 | View Code Duplication | class MailMakeCommand extends GeneratorCommand |
|
|
|||
12 | { |
||
13 | use ModuleCommandTrait; |
||
14 | |||
15 | /** |
||
16 | * The console command name. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name = 'module:make-mail'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Create a new email class for the specified module'; |
||
28 | |||
29 | protected $argumentName = 'name'; |
||
30 | |||
31 | 4 | public function getDefaultNamespace() : string |
|
37 | |||
38 | /** |
||
39 | * Get the console command arguments. |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | 120 | protected function getArguments() |
|
50 | |||
51 | /** |
||
52 | * Get template contents. |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | 4 | protected function getTemplateContents() |
|
65 | |||
66 | /** |
||
67 | * Get the destination file path. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 4 | protected function getDestinationFilePath() |
|
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 4 | private function getFileName() |
|
87 | } |
||
88 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.