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 |
||
22 | class XmlSettlementRequest extends XmlRequest |
||
23 | { |
||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $optionalParameters = array( |
||
28 | 'transtype', 'acqAuthorizationCode', 'errorEmail' |
||
29 | ); |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $apiEndpoint = 'XML_processor.jsp'; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $serviceName = 'paymentService'; |
||
40 | |||
41 | /** |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $serviceVersion = 3; |
||
45 | |||
46 | /** |
||
47 | * Settlement Debit/Credit |
||
48 | */ |
||
49 | const DATATRANS_REQUEST_TYPE_COA = 'COA'; |
||
50 | |||
51 | /** |
||
52 | * Submission of acqAuthorizationCode after referral |
||
53 | */ |
||
54 | const DATATRANS_REQUEST_TYPE_REF = 'REF'; |
||
55 | |||
56 | /** |
||
57 | * Submission of acqAuthorizationCode after denial |
||
58 | */ |
||
59 | const DATATRANS_REQUEST_TYPE_REC = 'REC'; |
||
60 | |||
61 | /** |
||
62 | * Transaction status request |
||
63 | */ |
||
64 | const DATATRANS_REQUEST_TYPE_STA = 'STA'; |
||
65 | |||
66 | /** |
||
67 | * Transaction cancel request |
||
68 | */ |
||
69 | const DATATRANS_REQUEST_TYPE_DOA = 'DOA'; |
||
70 | |||
71 | /** |
||
72 | * Re-Authorization of old transaction |
||
73 | */ |
||
74 | const DATATRANS_REQUEST_TYPE_REA = 'REA'; |
||
75 | |||
76 | /** |
||
77 | * Debit Transaction |
||
78 | */ |
||
79 | const DATATRANS_TRANSACTION_TYPE_DEBIT = '05'; |
||
80 | |||
81 | /** |
||
82 | * Credit Transaction |
||
83 | */ |
||
84 | const DATATRANS_TRANSACTION_TYPE_CREDIT = '06'; |
||
85 | |||
86 | /** |
||
87 | * @return array |
||
88 | */ |
||
89 | 6 | public function getData() |
|
120 | |||
121 | /** |
||
122 | * @param $value |
||
123 | * |
||
124 | * @return static |
||
125 | */ |
||
126 | 8 | public function setUppTransactionId($value) |
|
130 | |||
131 | /** |
||
132 | * @return string |
||
133 | */ |
||
134 | 8 | public function getUppTransactionId() |
|
138 | |||
139 | /** |
||
140 | * @param $value |
||
141 | * |
||
142 | * @return static |
||
143 | */ |
||
144 | public function setRequestType($value) |
||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | 5 | public function getRequestType() |
|
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | 2 | public function getTransactionType() |
|
164 | |||
165 | /** |
||
166 | * @param $data |
||
167 | * @return XmlResponse |
||
168 | */ |
||
169 | 8 | protected function createResponse($data) |
|
173 | } |
||
174 |
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.