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 SetCORSHeaders extends Command |
||
13 | { |
||
14 | /** |
||
15 | * The name and signature of the console command. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $signature = 'ovh:set-cors-headers |
||
20 | {--disk=ovh : The disk using your OVH container} |
||
21 | {--origins=* : The origins to be allowed on the containers (multiple allowed)} |
||
22 | {--max-age=3600 : The maximum cache validity of pre-flight requests} |
||
23 | {--force : Forcibly set the new headers}'; |
||
24 | |||
25 | /** |
||
26 | * The console command description. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $description = 'Set CORS headers on the container to make Form POST signaure work flawlessly'; |
||
31 | |||
32 | /** |
||
33 | * The Object Storage Container. |
||
34 | * |
||
35 | * @var Container |
||
36 | */ |
||
37 | protected $container; |
||
38 | |||
39 | /** array */ |
||
40 | protected $containerMeta = []; |
||
41 | |||
42 | /** |
||
43 | * Execute the console command. |
||
44 | * |
||
45 | * If the '--force' flag is provided, the specified keys will be set on the container. |
||
46 | * This excludes any 'Temp-Url-Key' already present on the container. |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | View Code Duplication | public function handle(): void |
|
72 | |||
73 | /** |
||
74 | * If there's no existing Temp URL Key present in the Container, continue. |
||
75 | * |
||
76 | * Otherwise, if there's already an existing Temp URL Key present in the |
||
77 | * Container, the User will be prompted to choose if we should override it |
||
78 | * or not. |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | protected function askIfShouldOverrideExistingParams(): bool |
||
95 | |||
96 | /** |
||
97 | * Updates the Temp URL Key for the Container. |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | protected function setHeaders(): void |
||
124 | } |
||
125 |
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.