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 PublishTranslationCommand extends Command |
|
|
|||
11 | { |
||
12 | /** |
||
13 | * The console command name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name = 'module:publish-translation'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Publish a module\'s translations to the application'; |
||
25 | |||
26 | /** |
||
27 | * Execute the console command. |
||
28 | * |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function fire() |
||
39 | |||
40 | /** |
||
41 | * Publish assets from all modules. |
||
42 | */ |
||
43 | public function publishAll() |
||
49 | |||
50 | /** |
||
51 | * Publish assets from the specified module. |
||
52 | * |
||
53 | * @param string $name |
||
54 | */ |
||
55 | public function publish($name) |
||
70 | |||
71 | /** |
||
72 | * Get the console command arguments. |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | 16 | protected function getArguments() |
|
82 | } |
||
83 |
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.