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 |
||
| 7 | class ExpressCheckout |
||
| 8 | { |
||
| 9 | // Integrate PayPal Request trait |
||
| 10 | use PayPalAPIRequest; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * PayPal Processor Constructor. |
||
| 14 | */ |
||
| 15 | public function __construct() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Function to perform SetExpressCheckout PayPal API operation. |
||
| 23 | * |
||
| 24 | * @param array $data |
||
| 25 | * @param bool $subscription |
||
| 26 | * |
||
| 27 | * @return array |
||
| 28 | */ |
||
| 29 | public function setExpressCheckout($data, $subscription = false) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Function to perform GetExpressCheckoutDetails PayPal API operation. |
||
| 72 | * |
||
| 73 | * @param string $token |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function getExpressCheckoutDetails($token) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Function to perform DoExpressCheckoutPayment PayPal API operation. |
||
| 88 | * |
||
| 89 | * @param array $data |
||
| 90 | * @param string $token |
||
| 91 | * @param string $payerid |
||
| 92 | * |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | public function doExpressCheckoutPayment($data, $token, $payerid) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Function to perform DoCapture PayPal API operation. |
||
| 122 | * |
||
| 123 | * @param string $authorization_id Transaction ID |
||
| 124 | * @param float $amount Amount to capture |
||
| 125 | * @param string $complete Indicates whether or not this is the last capture. |
||
| 126 | * @param array $data Optional request fields |
||
| 127 | * |
||
| 128 | * @return array |
||
| 129 | */ |
||
| 130 | public function doCapture($authorization_id, $amount, $complete = 'Complete', $data = []) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Function to perform DoAuthorization PayPal API operation. |
||
| 144 | * |
||
| 145 | * @param string $authorization_id Transaction ID |
||
| 146 | * @param float $amount Amount to capture |
||
| 147 | * @param array $data Optional request fields |
||
| 148 | * |
||
| 149 | * @return array |
||
| 150 | */ |
||
| 151 | View Code Duplication | public function doAuthorization($authorization_id, $amount, $data = []) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Function to perform DoVoid PayPal API operation. |
||
| 163 | * |
||
| 164 | * @param string $authorization_id Transaction ID |
||
| 165 | * @param array $data Optional request fields |
||
| 166 | * |
||
| 167 | * @return array |
||
| 168 | */ |
||
| 169 | View Code Duplication | public function doVoid($authorization_id, $data = []) |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Function to perform CreateBillingAgreement PayPal API operation. |
||
| 180 | * |
||
| 181 | * @param string $token |
||
| 182 | * |
||
| 183 | * @return array |
||
| 184 | */ |
||
| 185 | public function createBillingAgreement($token) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Function to perform CreateRecurringPaymentsProfile PayPal API operation. |
||
| 196 | * |
||
| 197 | * @param array $data |
||
| 198 | * @param string $token |
||
| 199 | * |
||
| 200 | * @return array |
||
| 201 | */ |
||
| 202 | public function createRecurringPaymentsProfile($data, $token) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Function to perform GetRecurringPaymentsProfileDetails PayPal API operation. |
||
| 213 | * |
||
| 214 | * @param string $id |
||
| 215 | * |
||
| 216 | * @return array |
||
| 217 | */ |
||
| 218 | public function getRecurringPaymentsProfileDetails($id) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Function to perform UpdateRecurringPaymentsProfile PayPal API operation. |
||
| 229 | * |
||
| 230 | * @param array $data |
||
| 231 | * @param string $id |
||
| 232 | * |
||
| 233 | * @return array |
||
| 234 | */ |
||
| 235 | public function updateRecurringPaymentsProfile($data, $id) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Function to cancel RecurringPaymentsProfile on PayPal. |
||
| 246 | * |
||
| 247 | * @param string $id |
||
| 248 | * |
||
| 249 | * @return array |
||
| 250 | */ |
||
| 251 | View Code Duplication | public function cancelRecurringPaymentsProfile($id) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * Function to suspend an active RecurringPaymentsProfile on PayPal. |
||
| 263 | * |
||
| 264 | * @param string $id |
||
| 265 | * |
||
| 266 | * @return array |
||
| 267 | */ |
||
| 268 | View Code Duplication | public function suspendRecurringPaymentsProfile($id) |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Function to reactivate a suspended RecurringPaymentsProfile on PayPal. |
||
| 280 | * |
||
| 281 | * @param string $id |
||
| 282 | * |
||
| 283 | * @return array |
||
| 284 | */ |
||
| 285 | View Code Duplication | public function reactivateRecurringPaymentsProfile($id) |
|
| 294 | } |
||
| 295 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..