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 Ideal extends OnlineBankTransferBase |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Payment method code |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $_code = PayoneConfig::METHOD_OBT_IDEAL; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Payment method sub type |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $sSubType = self::METHOD_OBT_SUBTYPE_IDEAL; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Array of all available bank groups |
||
| 54 | * |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected static $aBankGroups = [ |
||
| 58 | 'ABN_AMRO_BANK' => 'ABN Amro', |
||
| 59 | 'BUNQ_BANK' => 'Bunq', |
||
| 60 | 'ING_BANK' => 'ING Bank', |
||
| 61 | 'RABOBANK' => 'Rabobank', |
||
| 62 | 'SNS_BANK' => 'SNS Bank', |
||
| 63 | 'ASN_BANK' => 'ASN Bank', |
||
| 64 | 'SNS_REGIO_BANK' => 'Regio Bank', |
||
| 65 | 'TRIODOS_BANK' => 'Triodos Bank', |
||
| 66 | 'KNAB_BANK' => 'Knab', |
||
| 67 | 'VAN_LANSCHOT_BANKIERS' => 'van Lanschot', |
||
| 68 | ]; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Return parameters specific to this payment sub type |
||
| 72 | * |
||
| 73 | * @param Order $oOrder |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | View Code Duplication | public function getSubTypeSpecificParameters(Order $oOrder) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Add the checkout-form-data to the checkout session |
||
| 90 | * |
||
| 91 | * @param DataObject $data |
||
| 92 | * @return $this |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function assignData(DataObject $data) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Return available bank groups |
||
| 106 | * |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | View Code Duplication | public static function getBankGroups() |
|
| 122 | } |
||
| 123 |
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.