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 |
||
10 | View Code Duplication | class EventMakeCommand extends GeneratorCommand |
|
|
|||
11 | { |
||
12 | use ModuleCommandTrait; |
||
13 | |||
14 | protected $argumentName = 'name'; |
||
15 | |||
16 | /** |
||
17 | * The console command name. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name = 'module:make-event'; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = 'Create a new event class for the specified module'; |
||
29 | |||
30 | public function getTemplateContents() |
||
39 | |||
40 | public function getDestinationFilePath() |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | protected function getFileName() |
||
56 | |||
57 | public function getDefaultNamespace() : string |
||
61 | |||
62 | /** |
||
63 | * Get the console command arguments. |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | protected function getArguments() |
||
74 | } |
||
75 |
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.