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 Applications extends AriClientAware |
||
35 | { |
||
36 | /** |
||
37 | * List all getApplications. |
||
38 | * |
||
39 | * @return Application[] |
||
40 | */ |
||
41 | public function getApplications() |
||
53 | 1 | ||
54 | /** |
||
55 | 1 | * Get details of an application. |
|
56 | * |
||
57 | * @param $applicationName |
||
58 | * @return Application |
||
59 | * @throws NotFoundException |
||
60 | */ |
||
61 | View Code Duplication | public function getApplication($applicationName) |
|
72 | |||
73 | /** |
||
74 | 1 | * Subscribe an application to a event source. Returns the state of the application after the subscriptions have changed |
|
75 | * |
||
76 | * @param string $applicationName Application's name |
||
77 | * @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values. |
||
78 | * @return Application |
||
79 | * @throws InvalidParameterException |
||
80 | * @throws NotFoundException |
||
81 | * @throws UnprocessableEntityException Event source does not exist. |
||
82 | */ |
||
83 | public function subscribe($applicationName, $eventSource) |
||
98 | 1 | ||
99 | 1 | /** |
|
100 | * Unsubscribe an application from an event source. Returns the state of the application after the subscriptions have changed |
||
101 | * |
||
102 | 1 | * @param string $applicationName Application's name |
|
103 | * @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName} Allows comma separated values. |
||
104 | * @return Application |
||
105 | * @throws ConflictException |
||
106 | * @throws InvalidParameterException |
||
107 | * @throws NotFoundException |
||
108 | * @throws UnprocessableEntityException |
||
109 | */ |
||
110 | View Code Duplication | public function unsubscribe($applicationName, $eventSource) |
|
121 | } |
||
122 |
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.