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 |
||
| 37 | class ProviderSubjectLink extends ProviderParser { |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * @param IEvent $event |
||
| 42 | * @param Circle $circle |
||
| 43 | * @param FederatedLink $remote |
||
| 44 | * |
||
| 45 | * @throws FakeException |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function parseLinkRequestSent(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * @param IEvent $event |
||
| 64 | * @param Circle $circle |
||
| 65 | * @param FederatedLink $remote |
||
| 66 | * |
||
| 67 | * @throws FakeException |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function parseLinkRequestReceived(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * @param IEvent $event |
||
| 84 | * @param Circle $circle |
||
| 85 | * @param FederatedLink $remote |
||
| 86 | * |
||
| 87 | * @throws FakeException |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function parseLinkRequestRejected(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 101 | |||
| 102 | |||
| 103 | /** |
||
| 104 | * @param IEvent $event |
||
| 105 | * @param Circle $circle |
||
| 106 | * @param FederatedLink $remote |
||
| 107 | * |
||
| 108 | * @throws FakeException |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function parseLinkRequestCanceled(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * @param IEvent $event |
||
| 128 | * @param Circle $circle |
||
| 129 | * @param FederatedLink $remote |
||
| 130 | * |
||
| 131 | * @throws FakeException |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function parseLinkRequestAccepted(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 145 | |||
| 146 | |||
| 147 | /** |
||
| 148 | * @param IEvent $event |
||
| 149 | * @param Circle $circle |
||
| 150 | * @param FederatedLink $remote |
||
| 151 | * |
||
| 152 | * @throws FakeException |
||
| 153 | */ |
||
| 154 | View Code Duplication | public function parseLinkRequestRemoved(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 167 | |||
| 168 | |||
| 169 | /** |
||
| 170 | * @param IEvent $event |
||
| 171 | * @param Circle $circle |
||
| 172 | * @param FederatedLink $remote |
||
| 173 | * |
||
| 174 | * @throws FakeException |
||
| 175 | */ |
||
| 176 | View Code Duplication | public function parseLinkRequestCanceling(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 189 | |||
| 190 | |||
| 191 | /** |
||
| 192 | * @param IEvent $event |
||
| 193 | * @param Circle $circle |
||
| 194 | * @param FederatedLink $remote |
||
| 195 | * |
||
| 196 | * @throws FakeException |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function parseLinkRequestAccepting(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 211 | |||
| 212 | |||
| 213 | /** |
||
| 214 | * @param IEvent $event |
||
| 215 | * @param Circle $circle |
||
| 216 | * @param FederatedLink $remote |
||
| 217 | * |
||
| 218 | * @throws FakeException |
||
| 219 | */ |
||
| 220 | View Code Duplication | public function parseLinkUp(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 232 | |||
| 233 | |||
| 234 | /** |
||
| 235 | * @param IEvent $event |
||
| 236 | * @param Circle $circle |
||
| 237 | * @param FederatedLink $remote |
||
| 238 | * |
||
| 239 | * @throws FakeException |
||
| 240 | */ |
||
| 241 | View Code Duplication | public function parseLinkDown(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 255 | |||
| 256 | |||
| 257 | /** |
||
| 258 | * @param IEvent $event |
||
| 259 | * @param Circle $circle |
||
| 260 | * @param FederatedLink $remote |
||
| 261 | * |
||
| 262 | * @throws FakeException |
||
| 263 | */ |
||
| 264 | View Code Duplication | public function parseLinkRemove(IEvent &$event, Circle $circle, FederatedLink $remote) { |
|
| 277 | |||
| 278 | } |
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.