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 |
||
18 | class PublishDeleteAssignment extends Command |
||
19 | { |
||
20 | use InteractsWithEnvironment, |
||
21 | AborstIfEnvVariableIsnotInstalled, |
||
22 | InteractsWithAssignments, |
||
23 | ItFetchesAssignments; |
||
24 | |||
25 | /** |
||
26 | * The name and signature of the console command. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $signature = 'publish:delete_assignment {assignment? : The assignment to remove}' ; |
||
31 | |||
32 | /** |
||
33 | * The console command description. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $description = 'Deletes an assignment'; |
||
38 | |||
39 | /** |
||
40 | * Assignment. |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | protected $assignment; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Server names. |
||
49 | * |
||
50 | * @var Client |
||
51 | */ |
||
52 | protected $http; |
||
53 | |||
54 | /** |
||
55 | * SaveEnvVariable constructor. |
||
56 | * |
||
57 | */ |
||
58 | public function __construct(Client $http) |
||
63 | |||
64 | /** |
||
65 | * Execute the console command. |
||
66 | * |
||
67 | */ |
||
68 | View Code Duplication | public function handle() |
|
75 | |||
76 | /** |
||
77 | * Delete assignment. |
||
78 | * |
||
79 | * @return array|mixed |
||
80 | */ |
||
81 | protected function delete_assignment() |
||
98 | |||
99 | /** |
||
100 | * Abort command execution. |
||
101 | */ |
||
102 | protected function abortCommandExecution() |
||
106 | } |
||
107 |
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.