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 | class BackupCommandExport extends BackupCommandAbstract |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Name. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name = 'db:export'; |
||
18 | |||
19 | /** |
||
20 | * Description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Export the default database to `app/storage/backup`'; |
||
25 | |||
26 | /** |
||
27 | * Handle. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | public function handle(): void |
||
62 | |||
63 | /** |
||
64 | * Get the console command arguments. |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | protected function getArguments(): array |
||
74 | |||
75 | /** |
||
76 | * Get the console command options. |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | protected function getOptions(): array |
||
88 | } |
||
89 |
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.