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 |
||
| 38 | class MethodList |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * PAYONE consumerscore request model |
||
| 42 | * |
||
| 43 | * @var \Payone\Core\Model\Api\Request\Consumerscore |
||
| 44 | */ |
||
| 45 | protected $consumerscore; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Consumerscore helper |
||
| 49 | * |
||
| 50 | * @var \Payone\Core\Helper\Consumerscore |
||
| 51 | */ |
||
| 52 | protected $consumerscoreHelper; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Checkout session |
||
| 56 | * |
||
| 57 | * @var \Magento\Checkout\Model\Session |
||
| 58 | */ |
||
| 59 | protected $checkoutSession; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Payment ban entity |
||
| 63 | * |
||
| 64 | * @var \Payone\Core\Model\ResourceModel\PaymentBan |
||
| 65 | */ |
||
| 66 | protected $paymentBan; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Constructor |
||
| 70 | * |
||
| 71 | * @param \Payone\Core\Model\Api\Request\Consumerscore $consumerscore |
||
| 72 | * @param \Payone\Core\Helper\Consumerscore $consumerscoreHelper |
||
| 73 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
| 74 | * @param \Payone\Core\Model\ResourceModel\PaymentBan $paymentBan |
||
| 75 | */ |
||
| 76 | public function __construct( |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Filter methods by the worst score |
||
| 90 | * |
||
| 91 | * @param MethodInterface[] $aPaymentMethods |
||
| 92 | * @param string $sWorstScore |
||
| 93 | * @return MethodInterface[] |
||
| 94 | */ |
||
| 95 | protected function filterMethodsByScore($aPaymentMethods, $sWorstScore) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Execute a consumerscore request to PAYONE or load an old score if its lifetime is still active |
||
| 115 | * |
||
| 116 | * @param AddressInterface $oShipping |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | protected function getScoreByCreditrating(AddressInterface $oShipping) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Get parameter from config |
||
| 136 | * |
||
| 137 | * @param string $sParam |
||
| 138 | * @param bool $blIsAddresscheck |
||
| 139 | * @return string |
||
| 140 | */ |
||
| 141 | View Code Duplication | protected function getConfigParam($sParam, $blIsAddresscheck = false) |
|
| 149 | |||
| 150 | /** |
||
| 151 | * Get quote object from session |
||
| 152 | * |
||
| 153 | * @return Quote |
||
| 154 | */ |
||
| 155 | protected function getQuote() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Return banned payment methods for the current user |
||
| 162 | * |
||
| 163 | * @param Quote $oQuote |
||
| 164 | * @return array |
||
| 165 | */ |
||
| 166 | protected function getBannedPaymentMethods(Quote $oQuote) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Remove banned paymenttypes |
||
| 182 | * |
||
| 183 | * @param array $aPaymentMethods |
||
| 184 | * @param Quote $oQuote |
||
| 185 | * @return array |
||
| 186 | */ |
||
| 187 | protected function removeBannedPaymentMethods($aPaymentMethods, Quote $oQuote) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * |
||
| 204 | * @param OrigMethodList $subject |
||
| 205 | * @param MethodInterface[] $aPaymentMethods |
||
| 206 | * @return MethodInterface[] |
||
| 207 | */ |
||
| 208 | public function afterGetAvailableMethods(OrigMethodList $subject, $aPaymentMethods) |
||
| 232 | } |
||
| 233 |
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.