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 Klarna extends PayoneMethod |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Payment method code |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $_code = PayoneConfig::METHOD_KLARNA; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Info instructions block path |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $_infoBlockType = 'Payone\Core\Block\Info\SafeInvoice'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Clearingtype for PAYONE authorization request |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $sClearingtype = 'fnc'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Determines if the invoice information has to be added |
||
| 61 | * to the authorization-request |
||
| 62 | * |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $blNeedsProductInfo = true; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Keys that need to be assigned to the additionalinformation fields |
||
| 69 | * |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | protected $aAssignKeys = [ |
||
| 73 | 'telephone', |
||
| 74 | 'addinfo', |
||
| 75 | 'del_addinfo', |
||
| 76 | 'gender', |
||
| 77 | 'personal_id' |
||
| 78 | ]; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Map of value that can be directly added to the PAYONE request |
||
| 82 | * |
||
| 83 | * @var array |
||
| 84 | */ |
||
| 85 | protected $aDirectAssignMap = [ |
||
| 86 | 'telephone' => 'telephonenumber', |
||
| 87 | 'addinfo' => 'addressaddition', |
||
| 88 | 'del_addinfo' => 'shipping_addressaddition', |
||
| 89 | 'personal_id' => 'personalid', |
||
| 90 | 'dob' => 'birthday', |
||
| 91 | ]; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Return parameters specific to this payment type |
||
| 95 | * |
||
| 96 | * @param Order $oOrder |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | public function getPaymentSpecificParameters(Order $oOrder) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Returns formatted birthday if possible |
||
| 124 | * |
||
| 125 | * @param DataObject $data |
||
| 126 | * @return string|false |
||
| 127 | */ |
||
| 128 | View Code Duplication | protected function getFormattedBirthday(DataObject $data) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Add the checkout-form-data to the checkout session |
||
| 147 | * |
||
| 148 | * @param DataObject $data |
||
| 149 | * @return $this |
||
| 150 | */ |
||
| 151 | public function assignData(DataObject $data) |
||
| 171 | } |
||
| 172 |
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.