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 SafeInvoice extends PayoneMethod |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Payment method code |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $_code = PayoneConfig::METHOD_SAFE_INVOICE; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Clearingtype for PAYONE authorization request |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $sClearingtype = 'rec'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Determines if the invoice information has to be added |
||
| 54 | * to the authorization-request |
||
| 55 | * |
||
| 56 | * @var bool |
||
| 57 | */ |
||
| 58 | protected $blNeedsProductInfo = true; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Payment ban entity |
||
| 62 | * |
||
| 63 | * @var \Payone\Core\Model\ResourceModel\PaymentBan |
||
| 64 | */ |
||
| 65 | protected $paymentBan; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Payment ban duration in hours |
||
| 69 | * |
||
| 70 | * @var int |
||
| 71 | */ |
||
| 72 | protected $iBanDuration = 24; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Constructor |
||
| 76 | * |
||
| 77 | * @param \Magento\Framework\Model\Context $context |
||
| 78 | * @param \Magento\Framework\Registry $registry |
||
| 79 | * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory |
||
| 80 | * @param \Magento\Framework\Api\AttributeValueFactory $customAttrFactory |
||
| 81 | * @param \Magento\Payment\Helper\Data $paymentData |
||
| 82 | * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
||
| 83 | * @param \Magento\Payment\Model\Method\Logger $logger |
||
| 84 | * @param \Payone\Core\Helper\Toolkit $toolkitHelper |
||
| 85 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
| 86 | * @param \Magento\Framework\Url $url |
||
| 87 | * @param \Magento\Checkout\Model\Session $checkoutSession |
||
| 88 | * @param \Payone\Core\Model\Api\Request\Debit $debitRequest |
||
| 89 | * @param \Payone\Core\Model\Api\Request\Capture $captureRequest |
||
| 90 | * @param \Payone\Core\Model\Api\Request\Authorization $authorizationRequest |
||
| 91 | * @param \Payone\Core\Model\ResourceModel\PaymentBan $paymentBan |
||
| 92 | * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource |
||
| 93 | * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection |
||
| 94 | * @param array $data |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function __construct( |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Return parameters specific to this payment type |
||
| 122 | * |
||
| 123 | * @param Order $oOrder |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | public function getPaymentSpecificParameters(Order $oOrder) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Returns formatted birthday if possible |
||
| 146 | * |
||
| 147 | * @param DataObject $data |
||
| 148 | * @return string|false |
||
| 149 | */ |
||
| 150 | View Code Duplication | protected function getFormattedBirthday(DataObject $data) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Add the checkout-form-data to the checkout session |
||
| 169 | * |
||
| 170 | * @param DataObject $data |
||
| 171 | * @return $this |
||
| 172 | */ |
||
| 173 | public function assignData(DataObject $data) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Perform certain actions with the response |
||
| 188 | * |
||
| 189 | * @param array $aResponse |
||
| 190 | * @param Order $oOrder |
||
| 191 | * @return void |
||
| 192 | */ |
||
| 193 | protected function handleResponse($aResponse, Order $oOrder) |
||
| 210 | } |
||
| 211 |
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.