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 MigrateRollbackCommand extends ComponentCommand |
|
|
|||
12 | { |
||
13 | use MigrationLoaderTrait; |
||
14 | |||
15 | /** |
||
16 | * The console command name. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name = 'component:migrate-rollback'; |
||
21 | |||
22 | /** |
||
23 | * The console command description. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $description = 'Rollback the components migrations.'; |
||
28 | |||
29 | /** |
||
30 | * Execute the console command. |
||
31 | * |
||
32 | * @return mixed |
||
33 | */ |
||
34 | public function fire() |
||
50 | |||
51 | /** |
||
52 | * Rollback migration from the specified component. |
||
53 | * |
||
54 | * @param $component |
||
55 | */ |
||
56 | public function rollback($component) |
||
82 | |||
83 | /** |
||
84 | * Get the console command arguments. |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | protected function getArguments() |
||
94 | |||
95 | /** |
||
96 | * Get the console command options. |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | protected function getOptions() |
||
108 | } |
||
109 |
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.