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 |
||
8 | class Merchant extends Model |
||
9 | { |
||
10 | protected static $fields = MerchantFields::class; |
||
11 | |||
12 | /** |
||
13 | * You need to log into the MA site to obtain this value. This |
||
14 | * value will be different for test and live transactions. This |
||
15 | * should be located in a configuration file or extracted from |
||
16 | * a database. |
||
17 | * @var String |
||
18 | */ |
||
19 | private $merchantAccessCode; |
||
20 | |||
21 | /** |
||
22 | * This is a required field and may have |
||
23 | * a maximum of 40 alpha numeric characters. This |
||
24 | * reference should be unique for each transaction attempt |
||
25 | * and is used for the Query DR function. This field label is |
||
26 | * Merchant Transaction Reference in the Sample Code. |
||
27 | * |
||
28 | * @var String |
||
29 | */ |
||
30 | private $merchantTransactionReference; |
||
31 | |||
32 | /** |
||
33 | * Your Merchant ID is supplied in your Welcome Email. |
||
34 | * |
||
35 | * @var String |
||
36 | */ |
||
37 | private $merchantID; |
||
38 | |||
39 | 12 | public function __construct( |
|
50 | |||
51 | /** |
||
52 | * |
||
53 | * @param String $merchantAccessCode |
||
54 | * @param String $merchantTransactionReference |
||
55 | * @param String $merchantID |
||
56 | * @throws InvalidMerchantDetails |
||
57 | */ |
||
58 | 12 | private function validate( |
|
69 | |||
70 | 6 | View Code Duplication | public function toArray() : array |
78 | } |
||
79 |
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.