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 |
||
9 | View Code Duplication | final class NotificationMakeCommand extends GeneratorCommand |
|
|
|||
10 | { |
||
11 | |||
12 | use ModuleCommandTrait; |
||
13 | |||
14 | /** |
||
15 | * The console command name. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $name = 'module:make-notification'; |
||
20 | |||
21 | protected $argumentName = 'name'; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = 'Create a new notification class for the specified module.'; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | 2 | public function getDefaultNamespace() |
|
38 | |||
39 | |||
40 | /** |
||
41 | * Get template contents. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 2 | protected function getTemplateContents() |
|
54 | |||
55 | |||
56 | /** |
||
57 | * Get the destination file path. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | protected function getDestinationFilePath() |
|
69 | |||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | 2 | private function getFileName() |
|
78 | |||
79 | |||
80 | /** |
||
81 | * Get the console command arguments. |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | 60 | protected function getArguments() |
|
92 | } |
||
93 |
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.