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 Endpoints extends AriClientAware |
||
| 33 | { |
||
| 34 | const AST_ENDPOINT_UNKNOWN = 'unknown'; |
||
| 35 | const AST_ENDPOINT_OFFLINE = 'offline'; |
||
| 36 | const AST_ENDPOINT_ONLINE = 'online'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * List all endpoints. |
||
| 40 | * |
||
| 41 | * @return Endpoint |
||
| 42 | */ |
||
| 43 | 1 | View Code Duplication | public function getEndpoints() |
| 55 | |||
| 56 | /** |
||
| 57 | * Send a message to some technology URI or endpoint. |
||
| 58 | * |
||
| 59 | * @param string $to (required) The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp. |
||
| 60 | * @param string $from (required) The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp. |
||
| 61 | * @param string $body The body of the message |
||
| 62 | * @param array $variables |
||
| 63 | * @throws NotFoundException |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function sendMessage($to, $from, $body, $variables = array()) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * List available endoints for a given endpoint technology. |
||
| 84 | * |
||
| 85 | * @param string $tech Technology of the endpoints (sip,iax2,...) |
||
| 86 | * @return \phparia\Resources\Endpoint[] |
||
| 87 | * @throws NotFoundException |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function getEndpointsByTech($tech) |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Details for an endpoint. |
||
| 108 | * |
||
| 109 | * @param string $tech Technology of the endpoint |
||
| 110 | * @param string $resource ID of the endpoint |
||
| 111 | * @return Endpoint |
||
| 112 | * @throws InvalidParameterException |
||
| 113 | * @throws NotFoundException |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function getEndpointByTechAndResource($tech, $resource) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Send a message to some endpoint in a technology. |
||
| 129 | * |
||
| 130 | * @param string $tech |
||
| 131 | * @param $resource |
||
| 132 | * @param string $from (required) The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp. |
||
| 133 | * @param string $body The body of the message |
||
| 134 | * @param array $variables |
||
| 135 | * @throws InvalidParameterException |
||
| 136 | * @throws NotFoundException |
||
| 137 | * @internal param $string @resource |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function sendMessageToEndpointAndTechAndResource($tech, $resource, $from, $body, $variables = array()) |
|
| 154 | } |
||
| 155 |