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 Creditcard extends PayoneMethod |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Payment method code |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $_code = PayoneConfig::METHOD_CREDITCARD; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Info instructions block path |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $_infoBlockType = 'Payone\Core\Block\Info\Creditcard'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Clearingtype for PAYONE authorization request |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $sClearingtype = 'cc'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Determines if the redirect-parameters have to be added |
||
| 61 | * to the authorization-request |
||
| 62 | * |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $blNeedsRedirectUrls = true; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Return parameters specific to this payment type |
||
| 69 | * |
||
| 70 | * @param Order $oOrder |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function getPaymentSpecificParameters(Order $oOrder) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Add the checkout-form-data to the checkout session |
||
| 82 | * |
||
| 83 | * @param DataObject $data |
||
| 84 | * @return $this |
||
| 85 | */ |
||
| 86 | View Code Duplication | public function assignData(DataObject $data) |
|
| 95 | } |
||
| 96 |
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.