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 | class Bbb |
||
17 | { |
||
18 | use initMeeting; |
||
19 | |||
20 | private $response; |
||
21 | /** |
||
22 | * @var BigBlueButton |
||
23 | */ |
||
24 | protected $bbb; |
||
25 | |||
26 | |||
27 | public function __construct(BigBlueButton $bbb) |
||
31 | |||
32 | /* |
||
33 | * return BigBlueButton\BigBlueButton |
||
34 | * return BigBlueButton Class of Api class |
||
35 | */ |
||
36 | public function make() |
||
40 | /** |
||
41 | * Return a list of all meetings |
||
42 | * |
||
43 | * @return \Illuminate\Support\Collection |
||
44 | */ |
||
45 | public function all() |
||
61 | |||
62 | |||
63 | /** |
||
64 | * $meeting |
||
65 | * |
||
66 | * @param $meeting |
||
67 | * |
||
68 | * required fields |
||
69 | * meetingID |
||
70 | * meetingName |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | View Code Duplication | public function create($meeting) |
|
87 | |||
88 | /** |
||
89 | * @param $meeting |
||
90 | * |
||
91 | * required fields: |
||
92 | * meetingID |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function isMeetingRunning($meeting) |
||
112 | |||
113 | /** |
||
114 | * Join meeting |
||
115 | * |
||
116 | * @param $meeting |
||
117 | * required fields |
||
118 | * |
||
119 | * meetingID |
||
120 | * userName join by name |
||
121 | * password which role want to join |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function join($meeting) |
||
137 | |||
138 | /** |
||
139 | * Returns information about the meeting |
||
140 | * |
||
141 | * @param $meeting |
||
142 | * required fields |
||
143 | * meetingID |
||
144 | * moderatorPW must be there moderator password |
||
145 | * |
||
146 | * @return \Illuminate\Support\Collection |
||
147 | */ |
||
148 | View Code Duplication | public function getMeetingInfo($meeting) |
|
161 | |||
162 | /* |
||
163 | * required fields |
||
164 | * meetingID |
||
165 | * meetingName |
||
166 | * userName |
||
167 | * attendeePW |
||
168 | * moderatorPW |
||
169 | */ |
||
170 | public function start($parameters) |
||
174 | |||
175 | /** |
||
176 | * Close meeting |
||
177 | * |
||
178 | * @param $meeting |
||
179 | * required fields: |
||
180 | * meetingID |
||
181 | * moderatorPW close meeting must be there moderator password |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function close($meeting) |
||
198 | |||
199 | /** |
||
200 | * |
||
201 | * @param $recording |
||
202 | * required fields |
||
203 | * meetingID |
||
204 | * |
||
205 | * optional fields |
||
206 | * recordID |
||
207 | * state |
||
208 | * @return \Illuminate\Support\Collection |
||
209 | */ |
||
210 | public function getRecordings($recording) |
||
228 | |||
229 | /* |
||
230 | * required fields |
||
231 | * recordingID |
||
232 | */ |
||
233 | public function deleteRecordings($recording) |
||
242 | |||
243 | } |
||
244 |
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.