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 |
||
15 | View Code Duplication | class PublishNpm extends Command |
|
|
|||
16 | { |
||
17 | use ChecksEnv, RunsSSHCommands; |
||
18 | |||
19 | /** |
||
20 | * Server name |
||
21 | * |
||
22 | * @var String |
||
23 | */ |
||
24 | protected $server; |
||
25 | |||
26 | /** |
||
27 | * Domain |
||
28 | * |
||
29 | * @var String |
||
30 | */ |
||
31 | protected $domain; |
||
32 | |||
33 | /** |
||
34 | * The name and signature of the console command. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $signature = 'publish:npm {npm_command} {--server=} {--domain=}'; |
||
39 | |||
40 | /** |
||
41 | * The console command description. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $description = 'Run npm on production server'; |
||
46 | |||
47 | /** |
||
48 | * Guzzle http client. |
||
49 | * |
||
50 | * @var Client |
||
51 | */ |
||
52 | protected $http; |
||
53 | |||
54 | /** |
||
55 | * Create a new command instance. |
||
56 | * |
||
57 | */ |
||
58 | public function __construct(Client $http) |
||
63 | |||
64 | /** |
||
65 | * Execute the console command. |
||
66 | * |
||
67 | */ |
||
68 | public function handle() |
||
76 | |||
77 | /** |
||
78 | * Abort command execution? |
||
79 | */ |
||
80 | protected function abortCommandExecution() |
||
87 | } |
||
88 |
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.