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 |
||
16 | View Code Duplication | class PublishAssignmentGroups extends Command |
|
|
|||
17 | { |
||
18 | use InteractsWithLocalGithub, InteractsWithEnvironment; |
||
19 | |||
20 | use AborstIfEnvVariableIsnotInstalled; |
||
21 | |||
22 | /** |
||
23 | * The name and signature of the console command. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $signature = 'publish:assignment_groups {--group=* : The group/s assigned to this assignment}'; |
||
28 | |||
29 | /** |
||
30 | * The console command description. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $description = 'Assign a group of users to the current assignment'; |
||
35 | |||
36 | /** |
||
37 | * Server names. |
||
38 | * |
||
39 | * @var Client |
||
40 | */ |
||
41 | protected $http; |
||
42 | |||
43 | /** |
||
44 | * Groups |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $groups; |
||
49 | |||
50 | /** |
||
51 | * SaveEnvVariable constructor. |
||
52 | * |
||
53 | */ |
||
54 | public function __construct(Client $http) |
||
59 | |||
60 | /** |
||
61 | * Execute the console command. |
||
62 | * |
||
63 | */ |
||
64 | public function handle() |
||
71 | |||
72 | /** |
||
73 | * Assign groups to assignment |
||
74 | * |
||
75 | * @return array|mixed |
||
76 | */ |
||
77 | protected function assignGroupsToAssignment() |
||
98 | |||
99 | /** |
||
100 | * Ask for groups. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | protected function askForGroups() |
||
117 | |||
118 | /** |
||
119 | * Get groups |
||
120 | */ |
||
121 | protected function groups() |
||
138 | |||
139 | /** |
||
140 | * Abort command execution. |
||
141 | */ |
||
142 | protected function abortCommandExecution() |
||
146 | } |
||
147 |
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.