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 |
||
| 36 | class Payment extends \Payone\Core\Helper\Base |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * List of all currently available PAYONE payment types |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $aAvailablePayments = [ |
||
| 44 | PayoneConfig::METHOD_CREDITCARD, |
||
| 45 | PayoneConfig::METHOD_DEBIT, |
||
| 46 | PayoneConfig::METHOD_PAYPAL, |
||
| 47 | PayoneConfig::METHOD_CASH_ON_DELIVERY, |
||
| 48 | PayoneConfig::METHOD_ADVANCE_PAYMENT, |
||
| 49 | PayoneConfig::METHOD_INVOICE, |
||
| 50 | PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG, |
||
| 51 | PayoneConfig::METHOD_OBT_GIROPAY, |
||
| 52 | PayoneConfig::METHOD_OBT_EPS, |
||
| 53 | PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE, |
||
| 54 | PayoneConfig::METHOD_OBT_POSTFINANCE_CARD, |
||
| 55 | PayoneConfig::METHOD_OBT_IDEAL, |
||
| 56 | PayoneConfig::METHOD_OBT_PRZELEWY, |
||
| 57 | PayoneConfig::METHOD_BARZAHLEN, |
||
| 58 | PayoneConfig::METHOD_PAYDIREKT, |
||
| 59 | PayoneConfig::METHOD_SAFE_INVOICE, |
||
| 60 | PayoneConfig::METHOD_PAYOLUTION_INVOICE, |
||
| 61 | PayoneConfig::METHOD_PAYOLUTION_DEBIT, |
||
| 62 | PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT, |
||
| 63 | PayoneConfig::METHOD_ALIPAY |
||
| 64 | ]; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Mapping of payment method code to payment abbreviation |
||
| 68 | * |
||
| 69 | * @var array |
||
| 70 | */ |
||
| 71 | protected $aPaymentAbbreviation = [ |
||
| 72 | PayoneConfig::METHOD_CREDITCARD => 'cc', |
||
| 73 | PayoneConfig::METHOD_CASH_ON_DELIVERY => 'cod', |
||
| 74 | PayoneConfig::METHOD_DEBIT => 'elv', |
||
| 75 | PayoneConfig::METHOD_ADVANCE_PAYMENT => 'vor', |
||
| 76 | PayoneConfig::METHOD_INVOICE => 'rec', |
||
| 77 | PayoneConfig::METHOD_OBT_SOFORTUEBERWEISUNG => 'sb', |
||
| 78 | PayoneConfig::METHOD_OBT_GIROPAY => 'sb', |
||
| 79 | PayoneConfig::METHOD_OBT_EPS => 'sb', |
||
| 80 | PayoneConfig::METHOD_OBT_POSTFINANCE_EFINANCE => 'sb', |
||
| 81 | PayoneConfig::METHOD_OBT_POSTFINANCE_CARD => 'sb', |
||
| 82 | PayoneConfig::METHOD_OBT_IDEAL => 'sb', |
||
| 83 | PayoneConfig::METHOD_OBT_PRZELEWY => 'sb', |
||
| 84 | PayoneConfig::METHOD_PAYPAL => 'wlt', |
||
| 85 | PayoneConfig::METHOD_PAYDIREKT => 'wlt', |
||
| 86 | PayoneConfig::METHOD_BILLSAFE => 'fnc', |
||
| 87 | PayoneConfig::METHOD_KLARNA => 'fnc', |
||
| 88 | PayoneConfig::METHOD_BARZAHLEN => 'csh', |
||
| 89 | PayoneConfig::METHOD_SAFE_INVOICE => 'rec', |
||
| 90 | PayoneConfig::METHOD_PAYOLUTION_INVOICE => 'fnc', |
||
| 91 | PayoneConfig::METHOD_PAYOLUTION_DEBIT => 'fnc', |
||
| 92 | PayoneConfig::METHOD_PAYOLUTION_INSTALLMENT => 'fnc', |
||
| 93 | PayoneConfig::METHOD_ALIPAY => 'wlt', |
||
| 94 | ]; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Return available payment types |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 101 | public function getAvailablePaymentTypes() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Get all activated creditcard types |
||
| 108 | * |
||
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | View Code Duplication | public function getAvailableCreditcardTypes() |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Return if cvc has to be checked |
||
| 132 | * |
||
| 133 | * @return bool |
||
| 134 | */ |
||
| 135 | public function isCheckCvcActive() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Return if mandate management is activated |
||
| 142 | * |
||
| 143 | * @return bool |
||
| 144 | */ |
||
| 145 | public function isMandateManagementActive() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Return if mandate download is activated |
||
| 152 | * |
||
| 153 | * @return bool |
||
| 154 | */ |
||
| 155 | public function isMandateManagementDownloadActive() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Get status mapping configuration for given payment type |
||
| 162 | * |
||
| 163 | * @param string $sPaymentCode |
||
| 164 | * @return array |
||
| 165 | */ |
||
| 166 | public function getStatusMappingByCode($sPaymentCode) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Return display-message for the case that the bankaccount check |
||
| 183 | * returned, that the given bankaccount was blocked |
||
| 184 | * |
||
| 185 | * @return Phrase |
||
| 186 | */ |
||
| 187 | public function getBankaccountCheckBlockedMessage() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Return is PayPal Express is activated in the configuration |
||
| 198 | * |
||
| 199 | * @return bool |
||
| 200 | */ |
||
| 201 | public function isPayPalExpressActive() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Get abbreviation for the given payment type |
||
| 208 | * |
||
| 209 | * @param string $sPaymentCode |
||
| 210 | * @return string |
||
| 211 | */ |
||
| 212 | public function getPaymentAbbreviation($sPaymentCode) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Collect the Klarna store ids from the config and format it for frontend-use |
||
| 222 | * |
||
| 223 | * @return array |
||
| 224 | */ |
||
| 225 | public function getKlarnaStoreIds() |
||
| 238 | } |
||
| 239 |
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.