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 Events extends AriClientAware |
||
35 | { |
||
36 | /** |
||
37 | * WebSocket connection for events. |
||
38 | * |
||
39 | * @param string $app (required) Applications to subscribe to. Allows comma separated values. |
||
40 | * @param boolean $subscribeAll Subscribe to all Asterisk events. If provided, the applications listed will be subscribed to all events, effectively disabling the application specific subscriptions. Default is 'false'. |
||
41 | * @return EventInterface[] |
||
42 | */ |
||
43 | public function getEvents($app, $subscribeAll = false) |
||
60 | |||
61 | /** |
||
62 | * |
||
63 | * @param string $eventName Event name |
||
64 | * @param string $application (required) The name of the application that will receive this event |
||
65 | * @param string $source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName} Allows comma separated values. |
||
66 | * @param array $variables The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } |
||
67 | * } |
||
68 | * @throws InvalidParameterException |
||
69 | * @throws NotFoundException |
||
70 | * @throws UnprocessableEntityException |
||
71 | */ |
||
72 | View Code Duplication | public function createUserEvent($eventName, $application, $source, $variables = array()) |
|
87 | } |
||
88 |
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.