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 | class Publish extends SingleProductCommand |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'docweaver:publish |
||
18 | {product? : Product name} |
||
19 | {source? : Product repository} |
||
20 | {--y|y : Whether to skip confirmation} |
||
21 | '; |
||
22 | |||
23 | /** |
||
24 | * The console command description. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $description = 'Publish documentation for product'; |
||
29 | |||
30 | /** |
||
31 | * Execute the console command. |
||
32 | * |
||
33 | * @throws InvalidDirectory |
||
34 | */ |
||
35 | public function handle(): void |
||
59 | } |
||
60 |
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.