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 |
||
| 32 | class DeviceStates extends AriClientAware |
||
| 33 | { |
||
| 34 | const DEVICE_STATE_UNKNOWN = 'UNKNOWN'; |
||
| 35 | const DEVICE_STATE_NOT_INUSE = 'NOT_INUSE'; |
||
| 36 | const DEVICE_STATE_INUSE = 'INUSE'; |
||
| 37 | const DEVICE_STATE_BUSY = 'BUSY'; |
||
| 38 | const DEVICE_STATE_INVALID = 'INVALID'; |
||
| 39 | const DEVICE_STATE_UNAVAILABLE = 'UNAVAILABLE'; |
||
| 40 | const DEVICE_STATE_RINGING = 'RINGING'; |
||
| 41 | const DEVICE_STATE_RINGINUSE = 'RINGINUSE'; |
||
| 42 | const DEVICE_STATE_ONHOLD = 'ONHOLD'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * List all ARI controlled device states. |
||
| 46 | * |
||
| 47 | * @return DeviceState[] |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function getDeviceStates() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Retrieve the current state of a device. |
||
| 64 | * |
||
| 65 | * @param string $deviceName |
||
| 66 | * @return DeviceState |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function getDeviceState($deviceName) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Change the state of a device controlled by ARI. (Note - implicitly creates the device state). |
||
| 78 | * |
||
| 79 | * @param string $deviceName Name of the device |
||
| 80 | * @param string $deviceState (required) Device state value |
||
| 81 | * @throws ConflictException |
||
| 82 | * @throws NotFoundException |
||
| 83 | */ |
||
| 84 | public function updateDeviceState($deviceName, $deviceState) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Destroy a device-state controlled by ARI. |
||
| 100 | * |
||
| 101 | * @param string $deviceName Name of the device |
||
| 102 | * @throws ConflictException |
||
| 103 | * @throws NotFoundException |
||
| 104 | */ |
||
| 105 | public function deleteDeviceState($deviceName) |
||
| 114 | } |
||
| 115 |