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 |
||
33 | class Bridges extends MediaBase |
||
34 | { |
||
35 | /** |
||
36 | * List all active bridges in Asterisk. |
||
37 | * |
||
38 | * @return Bridge[] |
||
39 | */ |
||
40 | View Code Duplication | public function getBridges() |
|
52 | 2 | ||
53 | /** |
||
54 | * Create a new bridge. This bridge persists until it has been shut down, or Asterisk has been shut down. |
||
55 | * |
||
56 | * @param string $bridgeId Unique ID to give to the bridge being created. |
||
57 | * @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media). |
||
58 | * @param string $name Name to give to the bridge being created. |
||
59 | * @return Bridge |
||
60 | */ |
||
61 | public function createBridge($bridgeId, $type, $name) |
||
74 | |||
75 | /** |
||
76 | * Create a new bridge or updates an existing one. This bridge persists until it has been shut down, or Asterisk has been shut down. |
||
77 | * |
||
78 | * @param string $bridgeId Unique ID to give to the bridge being created. |
||
79 | * @param string $type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set. |
||
80 | * @param string $name Set the name of the bridge. |
||
81 | * @return Bridge |
||
82 | */ |
||
83 | public function updateBridge($bridgeId, $type, $name) |
||
95 | |||
96 | /** |
||
97 | * Get bridge details. |
||
98 | * |
||
99 | * @param string $bridgeId Bridge's id |
||
100 | * @return Bridge |
||
101 | 9 | * @throws NotFoundException |
|
102 | */ |
||
103 | 9 | View Code Duplication | public function getBridge($bridgeId) |
114 | |||
115 | /** |
||
116 | * Shut down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand. |
||
117 | * |
||
118 | * @param string $bridgeId Bridge's id |
||
119 | 14 | * @throws NotFoundException |
|
120 | */ |
||
121 | 14 | public function deleteBridge($bridgeId) |
|
130 | |||
131 | /** |
||
132 | * Add a channel to a bridge. |
||
133 | * |
||
134 | * @param string $bridgeId Bridge's id |
||
135 | * @param string $channel (required) Ids of channels to add to bridge. Allows comma separated values. |
||
136 | * @param string $role Channel's role in the bridge |
||
137 | * @throws NotFoundException |
||
138 | * @throws ConflictException |
||
139 | 12 | * @throws UnprocessableEntityException |
|
140 | */ |
||
141 | 12 | public function addChannel($bridgeId, $channel, $role = null) |
|
155 | |||
156 | 8 | /** |
|
157 | * Remove a channel from a bridge. |
||
158 | * |
||
159 | * @param string $bridgeId Bridge's id |
||
160 | * @param string $channel (required) Ids of channels to remove from bridge. Allows comma separated values. |
||
161 | * @throwe InvalidParameterException |
||
162 | * @throws NotFoundException |
||
163 | * @throws ConflictException |
||
164 | * @throws UnprocessableEntityException |
||
165 | */ |
||
166 | public function removeChannel($bridgeId, $channel) |
||
179 | |||
180 | public function getType() |
||
184 | } |
||
185 |
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.