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 |
||
25 | class ThirdPartyApiClient extends CommonProductsThirdPartyApiClient implements ThirdPartyApiClientInterface |
||
26 | { |
||
27 | const SUB_URL_BUSINESS_INFO = 'api/business/%s/plugins'; |
||
28 | const SUB_URL_CONNECTION = 'api/business/%s/connection/authorization/%s'; |
||
29 | const SUB_URL_INTEGRATION = 'api/business/%s/integration/%s'; |
||
30 | |||
31 | /** |
||
32 | * @inheritdoc |
||
33 | * |
||
34 | * @throws \Exception |
||
35 | */ |
||
36 | public function getBusinessRequest() |
||
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | * |
||
53 | * @throws \Exception |
||
54 | */ |
||
55 | public function getSubscriptionStatus(SubscriptionRequestEntity $requestEntity) |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | * |
||
74 | * @throws \Exception |
||
75 | */ |
||
76 | public function subscribe(SubscriptionRequestEntity $requestEntity) |
||
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | * |
||
97 | * @throws \Exception |
||
98 | */ |
||
99 | public function unsubscribe(SubscriptionRequestEntity $requestEntity) |
||
114 | |||
115 | /** |
||
116 | * @param string $businessUuid |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | protected function getBusinessInfoUrl($businessUuid) |
||
124 | |||
125 | /** |
||
126 | * @param SubscriptionRequestEntity $requestEntity |
||
127 | * @return string |
||
128 | */ |
||
129 | View Code Duplication | protected function getConnectionUrl(SubscriptionRequestEntity $requestEntity) |
|
139 | |||
140 | /** |
||
141 | * @param SubscriptionRequestEntity $requestEntity |
||
142 | * @return string |
||
143 | */ |
||
144 | View Code Duplication | protected function getIntegrationUrl(SubscriptionRequestEntity $requestEntity) |
|
154 | |||
155 | /** |
||
156 | * @param SubscriptionRequestEntity $requestEntity |
||
157 | */ |
||
158 | private function fillSubscriptionEntityFromConfiguration(SubscriptionRequestEntity $requestEntity) |
||
167 | } |
||
168 |
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.