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 |
||
17 | class PublishDeploymentScriptWithHooks extends Command |
||
18 | { |
||
19 | use ChecksEnv, DiesIfEnvVariableIsnotInstalled; |
||
20 | |||
21 | /** |
||
22 | * The name and signature of the console command. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $signature = 'publish:deployment_script_with_hooks {--domain=}'; |
||
27 | |||
28 | /** |
||
29 | * The console command description. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $description = 'Install deployment script with hooks'; |
||
34 | |||
35 | /** |
||
36 | * Domain. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $domain; |
||
41 | |||
42 | /** |
||
43 | * Compiler for llumrc file. |
||
44 | * |
||
45 | * @var RCFileCompiler |
||
46 | */ |
||
47 | protected $compiler; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | * |
||
52 | */ |
||
53 | public function __construct(RCFileCompiler $compiler) |
||
58 | |||
59 | /** |
||
60 | * Execute the console command. |
||
61 | * |
||
62 | */ |
||
63 | public function handle() |
||
80 | |||
81 | /** |
||
82 | * Get stub path. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | protected function getStubPath() |
||
90 | |||
91 | |||
92 | |||
93 | /** |
||
94 | * Update deployment script. |
||
95 | */ |
||
96 | View Code Duplication | protected function updateDeploymentScript() |
|
118 | |||
119 | /** |
||
120 | * Obtain API URL endpoint. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | protected function obtainAPIURLEndpoint($type) |
||
130 | |||
131 | /** |
||
132 | * Abort command execution. |
||
133 | */ |
||
134 | protected function abortCommandExecution() |
||
138 | } |
||
139 |
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.