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 |
||
12 | class ModuleMigrateRollbackCommand extends Command |
||
13 | { |
||
14 | use MigrationTrait, ConfirmableTrait; |
||
15 | |||
16 | /** |
||
17 | * The console command name. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name = 'module:migrate:rollback'; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = 'Rollback the last database migrations for a specific or all modules'; |
||
29 | |||
30 | /** |
||
31 | * @var Modules |
||
32 | */ |
||
33 | protected $module; |
||
34 | |||
35 | /** |
||
36 | * Create a new command instance. |
||
37 | * |
||
38 | * @param Modules $module |
||
39 | */ |
||
40 | public function __construct(Modules $module) |
||
46 | |||
47 | /** |
||
48 | * Execute the console command. |
||
49 | * |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function fire() |
||
68 | |||
69 | /** |
||
70 | * Run the migration rollback for the specified module. |
||
71 | * |
||
72 | * @param string $slug |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | protected function rollback($slug) |
||
77 | { |
||
78 | $this->requireMigrations($slug); |
||
79 | |||
80 | $this->call('migrate:rollback', [ |
||
81 | '--database' => $this->option('database'), |
||
82 | '--force' => $this->option('force'), |
||
83 | '--pretend' => $this->option('pretend'), |
||
84 | ]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get the console command arguments. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | protected function getArguments() |
||
96 | |||
97 | /** |
||
98 | * Get the console command options. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | View Code Duplication | protected function getOptions() |
|
110 | } |
||
111 |
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.