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 |
||
| 39 | class Asterisk extends AriClientAware |
||
| 40 | { |
||
| 41 | const INFO_BUILD = 'build'; |
||
| 42 | const INFO_SYSTEM = 'system'; |
||
| 43 | const INFO_CONFIG = 'config'; |
||
| 44 | const INFO_STATUS = 'status'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Retrieve a dynamic configuration object. |
||
| 48 | * |
||
| 49 | * @param string $configClass The configuration class containing dynamic configuration objects. |
||
| 50 | * @param string $objectType The type of configuration object to retrieve. |
||
| 51 | * @param string $id The unique identifier of the object to retrieve. |
||
| 52 | * @return ConfigTuple[] |
||
| 53 | * @throws NotFoundException |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function getObject($configClass, $objectType, $id) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Create or update a dynamic configuration object. |
||
| 75 | * |
||
| 76 | * @param string $configClass The configuration class containing dynamic configuration objects. |
||
| 77 | * @param string $objectType The type of configuration object to retrieve. |
||
| 78 | * @param string $id The unique identifier of the object to retrieve. |
||
| 79 | * @param ConfigTuple[] $fields The body object should have a value that is a list of ConfigTuples, which provide the fields to update. Ex. [ { "attribute": "directmedia", "value": "false" } ] |
||
| 80 | * @return ConfigTuple[] |
||
| 81 | * @throws BadResponseException |
||
| 82 | * @throws ForbiddenException |
||
| 83 | * @throws NotFoundException |
||
| 84 | */ |
||
| 85 | public function updateObject($configClass, $objectType, $id, $fields) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Delete a dynamic configuration object. |
||
| 109 | * |
||
| 110 | * @param string $configClass The configuration class containing dynamic configuration objects. |
||
| 111 | * @param string $objectType The type of configuration object to retrieve. |
||
| 112 | * @param string $id The unique identifier of the object to retrieve. |
||
| 113 | * @throws ForbiddenException |
||
| 114 | * @throws NotFoundException |
||
| 115 | */ |
||
| 116 | public function deleteObject($configClass, $objectType, $id) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Gets Asterisk system information. |
||
| 129 | * |
||
| 130 | * @param string $only Filter information returned. Allows comma separated values. Allowed values: build, system, config, status. |
||
| 131 | * @return AsteriskInfo |
||
| 132 | */ |
||
| 133 | 2 | public function getInfo($only = null) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * List Asterisk modules. |
||
| 147 | * |
||
| 148 | * @return Module[] |
||
| 149 | */ |
||
| 150 | View Code Duplication | public function listModules() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Get Asterisk module information. |
||
| 166 | * |
||
| 167 | * @param string $moduleName Module's name |
||
| 168 | * @return Module |
||
| 169 | * @throws NotFoundException |
||
| 170 | * @throws ConflictException |
||
| 171 | */ |
||
| 172 | View Code Duplication | public function getModule($moduleName) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Load an Asterisk module. |
||
| 183 | * |
||
| 184 | * @param string $moduleName Module's name |
||
| 185 | * @return Module |
||
| 186 | * @throws ConflictException |
||
| 187 | */ |
||
| 188 | public function loadModule($moduleName) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Unload an Asterisk module. |
||
| 197 | * |
||
| 198 | * @param string $moduleName Module's name |
||
| 199 | * @return Module |
||
| 200 | * @throws NotFoundException |
||
| 201 | * @throws ConflictException |
||
| 202 | */ |
||
| 203 | public function unloadModule($moduleName) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Reload an Asterisk module. |
||
| 212 | * |
||
| 213 | * @param string $moduleName Module's name |
||
| 214 | * @return Module |
||
| 215 | * @throws NotFoundException |
||
| 216 | * @throws ConflictException |
||
| 217 | */ |
||
| 218 | public function reloadModule($moduleName) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Gets Asterisk log channel information. |
||
| 227 | * |
||
| 228 | * @return LogChannel[] |
||
| 229 | */ |
||
| 230 | View Code Duplication | public function listLogChannels() |
|
| 243 | |||
| 244 | /** |
||
| 245 | * Adds a log channel. |
||
| 246 | * |
||
| 247 | * @param string $logChannelName |
||
| 248 | * @param string $configuration |
||
| 249 | * @throws InvalidParameterException |
||
| 250 | * @throws ConflictException |
||
| 251 | */ |
||
| 252 | public function addLog($logChannelName, $configuration) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Deletes a log channel. |
||
| 269 | * |
||
| 270 | * @param string $logChannelName |
||
| 271 | * @throws NotFoundException |
||
| 272 | */ |
||
| 273 | public function deleteLog($logChannelName) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Rotates a log channel. |
||
| 286 | * |
||
| 287 | * @param string $logChannelName |
||
| 288 | * @throws NotFoundException |
||
| 289 | */ |
||
| 290 | public function rotateLog($logChannelName) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Get the value of a global variable. |
||
| 303 | * |
||
| 304 | * @param string $variable (required) The variable to get |
||
| 305 | * @return Variable |
||
| 306 | * @throws InvalidParameterException |
||
| 307 | */ |
||
| 308 | 1 | View Code Duplication | public function getGlobalVar($variable) |
| 320 | |||
| 321 | /** |
||
| 322 | * Get the value of a global variable. |
||
| 323 | * |
||
| 324 | * @param string $variable (required) The variable to get |
||
| 325 | * @return Variable |
||
| 326 | * @throws InvalidParameterException |
||
| 327 | * @deprecated |
||
| 328 | */ |
||
| 329 | 1 | public function getVariable($variable) |
|
| 333 | |||
| 334 | /** |
||
| 335 | * Set the value of a global variable. |
||
| 336 | * |
||
| 337 | * @param string $variable (required) The variable to set |
||
| 338 | * @param string $value The value to set the variable to |
||
| 339 | * @throws InvalidParameterException |
||
| 340 | */ |
||
| 341 | 1 | public function setGlobalVar($variable, $value = null) |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Set the value of a global variable. |
||
| 359 | * |
||
| 360 | * @param string $variable (required) The variable to set |
||
| 361 | * @param string $value The value to set the variable to |
||
| 362 | * @throws InvalidParameterException |
||
| 363 | * @deprecated |
||
| 364 | */ |
||
| 365 | 1 | public function setVariable($variable, $value) |
|
| 369 | } |
||
| 370 |