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 |
||
34 | class Recordings extends AriClientAware |
||
35 | { |
||
36 | /** |
||
37 | * List recordings that are complete. |
||
38 | * |
||
39 | * @return StoredRecording[] |
||
40 | */ |
||
41 | 2 | public function getRecordings() |
|
53 | |||
54 | /** |
||
55 | * Get a stored recording's details. |
||
56 | * |
||
57 | * @param string $recordingName The name of the recording |
||
58 | * @return StoredRecording |
||
59 | * @throws NotFoundException |
||
60 | */ |
||
61 | 3 | public function getRecording($recordingName) |
|
72 | |||
73 | /** |
||
74 | * Delete a stored recording. |
||
75 | * |
||
76 | * @param string $recordingName The name of the recording |
||
77 | * @return StoredRecording |
||
78 | * @throws NotFoundException |
||
79 | */ |
||
80 | 2 | View Code Duplication | public function deleteRecording($recordingName) |
89 | |||
90 | /** |
||
91 | * Copy a stored recording. |
||
92 | * |
||
93 | * @param string $recordingName The name of the recording to copy |
||
94 | * @param string $destinationRecordingName (required) The destination name of the recording |
||
95 | * @return StoredRecording |
||
96 | * @throws ConflictException |
||
97 | * @throws NotFoundException |
||
98 | */ |
||
99 | 1 | View Code Duplication | public function copyRecording($recordingName, $destinationRecordingName) |
114 | |||
115 | /** |
||
116 | * Get live recording |
||
117 | * |
||
118 | * @param string $recordingName The name of the recording |
||
119 | * @return LiveRecording |
||
120 | * @throws NotFoundException |
||
121 | */ |
||
122 | public function getLiveRecording($recordingName) |
||
133 | |||
134 | /** |
||
135 | * Stop a live recording and discard it. |
||
136 | * |
||
137 | * @param string $recordingName The name of the recording |
||
138 | * @throws NotFoundException |
||
139 | */ |
||
140 | View Code Duplication | public function deleteLiveRecording($recordingName) |
|
149 | |||
150 | /** |
||
151 | * Stop a live recording and store it. |
||
152 | * |
||
153 | * @param string $recordingName The name of the recording |
||
154 | * @throws NotFoundException |
||
155 | */ |
||
156 | View Code Duplication | public function stopLiveRecording($recordingName) |
|
165 | |||
166 | /** |
||
167 | * Pause a live recording. Pausing a recording suspends silence detection, which will be restarted |
||
168 | * when the recording is unpaused. Paused time is not included in the accounting for |
||
169 | * maxDurationSeconds. |
||
170 | * |
||
171 | * @param string $recordingName The name of the recording |
||
172 | * @throws ConflictException |
||
173 | * @throws NotFoundException |
||
174 | */ |
||
175 | View Code Duplication | public function pauseLiveRecording($recordingName) |
|
186 | |||
187 | /** |
||
188 | * Unause a live recording. |
||
189 | * |
||
190 | * @param string $recordingName The name of the recording |
||
191 | * @throws ConflictException |
||
192 | * @throws NotFoundException |
||
193 | */ |
||
194 | View Code Duplication | public function unpauseLiveRecording($recordingName) |
|
205 | |||
206 | /** |
||
207 | * Mute a live recording. Muting a recording suspends silence detection, which will be restarted when the recording is unmuted. |
||
208 | * |
||
209 | * @param string $recordingName The name of the recording |
||
210 | * @throws ConflictException |
||
211 | * @throws NotFoundException |
||
212 | */ |
||
213 | View Code Duplication | public function muteLiveRecording($recordingName) |
|
224 | |||
225 | /** |
||
226 | * Unmute a live recording. |
||
227 | * |
||
228 | * @param string $recordingName The name of the recording |
||
229 | * @throws ConflictException |
||
230 | * @throws NotFoundException |
||
231 | */ |
||
232 | View Code Duplication | public function unmuteLiveRecording($recordingName) |
|
243 | |||
244 | } |
||
245 |
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.