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 |
||
| 35 | abstract class MediaBase extends AriClientAware |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @return string 'channels' or 'bridges' |
||
| 39 | */ |
||
| 40 | abstract public function getType(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Play music on hold to a channel. Using media operations such as /play on a channel playing MOH in |
||
| 44 | * this manner will suspend MOH without resuming automatically. If continuing music on hold is |
||
| 45 | * desired, the stasis application must reinitiate music on hold. |
||
| 46 | * |
||
| 47 | * @param string $id Bridge/Channel's id |
||
| 48 | * @param string $mohClass Music on hold class to use |
||
| 49 | * @throws NotFoundException |
||
| 50 | * @throws ConflictException |
||
| 51 | */ |
||
| 52 | public function startMusicOnHold($id, $mohClass) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Stop playing music on hold to a channel. |
||
| 68 | * |
||
| 69 | * @param string $id Bridge/Channel's id |
||
| 70 | * @throws NotFoundException |
||
| 71 | * @throws ConflictException |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function stopMusicOnHold($id) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Start playback of media. The media URI may be any of a number of URI's. Currently sound:, |
||
| 85 | * recording:, number:, digits:, characters:, and tone: URI's are supported. This operation creates a |
||
| 86 | * playback resource that can be used to control the playback of media (pause, rewind, fast forward, |
||
| 87 | * etc.) |
||
| 88 | * |
||
| 89 | * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback |
||
| 90 | * |
||
| 91 | * @param string $id Bridge/Channel's id |
||
| 92 | * @param string $media (required) Media's URI to play. |
||
| 93 | * @param string $lang For sounds, selects language for sound. |
||
| 94 | * @param int $offsetms Number of media to skip before playing. |
||
| 95 | * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations. |
||
| 96 | * @param string $playbackId Playback Id. |
||
| 97 | * @return Playback |
||
| 98 | * @throws NotFoundException |
||
| 99 | * @throws ConflictException |
||
| 100 | */ |
||
| 101 | View Code Duplication | public function playMedia($id, $media, $lang = null, $offsetms = null, $skipms = null, $playbackId = null) |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Start playback of media and specify the playbackId. The media URI may be any of a number of URI's. |
||
| 124 | * Currently sound: and recording: URI's are supported. This operation creates a playback resource |
||
| 125 | * that can be used to control the playback of media (pause, rewind, fast forward, etc.) |
||
| 126 | * |
||
| 127 | * @link https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Simple+Media+Manipulation Simple media playback |
||
| 128 | * |
||
| 129 | * @param string $id Channel's id |
||
| 130 | * @param string $media (required) Media's URI to play. |
||
| 131 | * @param string $lang For sounds, selects language for sound. |
||
| 132 | * @param int $offsetms Number of media to skip before playing. |
||
| 133 | * @param int $skipms (3000 default) Number of milliseconds to skip for forward/reverse operations. |
||
| 134 | * @param string $playbackId Playback Id. |
||
| 135 | * @return Playback |
||
| 136 | * @throws NotFoundException |
||
| 137 | * @throws ConflictException |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function playMediaWithId( |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Start a recording. Record audio from a channel. Note that this will not capture audio sent to the |
||
| 166 | * channel. The bridge itself has a record feature if that's what you want. |
||
| 167 | * |
||
| 168 | * @param string $id Channel/Bridge ID |
||
| 169 | * @param string $name (required) Recording's filename |
||
| 170 | * @param string $format (required) Format to encode audio in |
||
| 171 | * @param int $maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit |
||
| 172 | * @param int $maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit |
||
| 173 | * @param string $ifExists = fail - Action to take if a recording with the same name already exists. |
||
| 174 | * @param boolean $beep string = fail - Action to take if a recording with the same name already exists. |
||
| 175 | * @param string $terminateOn none - DTMF input to terminate recording |
||
| 176 | * @return LiveRecording |
||
| 177 | * @throws InvalidParameterException |
||
| 178 | * @throws NotFoundException |
||
| 179 | * @throws ConflictException |
||
| 180 | * @throws UnprocessableEntityException |
||
| 181 | */ |
||
| 182 | public function record( |
||
| 211 | } |
||
| 212 |