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 namespace Savannabits\JetstreamInertiaGenerator\Generators; |
||
5 | View Code Duplication | class DestroyRequest extends ClassGenerator { |
|
|
|||
6 | |||
7 | /** |
||
8 | * The name and signature of the console command. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $name = 'jig:generate:request:destroy'; |
||
13 | |||
14 | /** |
||
15 | * The console command description. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $description = 'Generate a Destroy request class'; |
||
20 | |||
21 | /** |
||
22 | * Execute the console command. |
||
23 | * |
||
24 | * @return void |
||
25 | */ |
||
26 | public function handle() |
||
34 | |||
35 | protected function buildClass() :string { |
||
45 | |||
46 | protected function getOptions() { |
||
52 | |||
53 | public function generateClassNameFromTable($tableName) :string { |
||
56 | |||
57 | /** |
||
58 | * Get the default namespace for the class. |
||
59 | * |
||
60 | * @param string $rootNamespace |
||
61 | * @return string |
||
62 | */ |
||
63 | protected function getDefaultNamespace(string $rootNamespace) :string |
||
67 | |||
68 | } |
||
69 |
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.