Total Complexity | 42 |
Total Lines | 273 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like PurchaseRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PurchaseRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class PurchaseRequest extends AbstractRequest { |
||
12 | |||
13 | const EP_HOST_TEST = 'https://mti.bankmuscat.com:6443/transaction.do?command=initiateTransaction'; |
||
14 | const EP_HOST_LIVE = 'https://smartpaytrns.bankmuscat.com/transaction.do?command=initiateTransaction'; |
||
15 | |||
16 | public function initialize(array $parameters = []) |
||
17 | { |
||
18 | return parent::initialize($parameters); |
||
19 | } |
||
20 | |||
21 | public function getMerchantId() |
||
22 | { |
||
23 | return $this->getParameter('merchantId'); |
||
24 | } |
||
25 | |||
26 | public function setMerchantId($merchantId) |
||
27 | { |
||
28 | return $this->setParameter('merchantId', $merchantId); |
||
29 | } |
||
30 | |||
31 | public function getAccessCode() |
||
32 | { |
||
33 | return $this->getParameter('accessCode'); |
||
34 | } |
||
35 | |||
36 | public function setAccessCode($accessCode) |
||
37 | { |
||
38 | return $this->setParameter('accessCode', $accessCode); |
||
39 | } |
||
40 | |||
41 | public function getWorkingKey() |
||
42 | { |
||
43 | return $this->getParameter('workingKey'); |
||
44 | } |
||
45 | |||
46 | public function setWorkingKey($workingKey) |
||
47 | { |
||
48 | return $this->setParameter('workingKey', $workingKey); |
||
49 | } |
||
50 | |||
51 | public function getOrderId() |
||
52 | { |
||
53 | return $this->getParameter('orderId'); |
||
54 | } |
||
55 | |||
56 | public function setOrderId($orderId) |
||
57 | { |
||
58 | return $this->setParameter('orderId', $orderId); |
||
59 | } |
||
60 | |||
61 | public function getMerchantParameter1() |
||
62 | { |
||
63 | return $this->getParameter('merchantParameter1'); |
||
64 | } |
||
65 | |||
66 | public function setMerchantParameter1($parameter) |
||
67 | { |
||
68 | return $this->setParameter('merchantParameter1', $parameter); |
||
69 | } |
||
70 | |||
71 | public function getMerchantParameter2() |
||
72 | { |
||
73 | return $this->getParameter('merchantParameter2'); |
||
74 | } |
||
75 | |||
76 | public function setMerchantParameter2($parameter) |
||
77 | { |
||
78 | return $this->setParameter('merchantParameter2', $parameter); |
||
79 | } |
||
80 | |||
81 | public function getMerchantParameter3() |
||
82 | { |
||
83 | return $this->getParameter('merchantParameter3'); |
||
84 | } |
||
85 | |||
86 | public function setMerchantParameter3($parameter) |
||
87 | { |
||
88 | return $this->setParameter('merchantParameter3', $parameter); |
||
89 | } |
||
90 | |||
91 | public function getMerchantParameter4() |
||
92 | { |
||
93 | return $this->getParameter('merchantParameter4'); |
||
94 | } |
||
95 | |||
96 | public function setMerchantParameter4($parameter) |
||
97 | { |
||
98 | return $this->setParameter('merchantParameter4', $parameter); |
||
99 | } |
||
100 | |||
101 | public function getMerchantParameter5() |
||
102 | { |
||
103 | return $this->getParameter('merchantParameter5'); |
||
104 | } |
||
105 | |||
106 | public function setMerchantParameter5($parameter) |
||
107 | { |
||
108 | return $this->setParameter('merchantParameter5', $parameter); |
||
109 | } |
||
110 | |||
111 | public function setBillingName($billingName) |
||
112 | { |
||
113 | return $this->setParameter('billingName', $billingName); |
||
114 | } |
||
115 | |||
116 | public function getBillingName() |
||
117 | { |
||
118 | return $this->getParameter('billingName'); |
||
119 | } |
||
120 | |||
121 | public function setBillingAddress($billingAddress) |
||
122 | { |
||
123 | return $this->setParameter('billingAddress', $billingAddress); |
||
124 | } |
||
125 | |||
126 | public function getBillingAddress() |
||
129 | } |
||
130 | |||
131 | public function setBillingCity($billingCity) |
||
132 | { |
||
133 | return $this->setParameter('billingCity', $billingCity); |
||
134 | } |
||
135 | |||
136 | public function getBillingCity() |
||
137 | { |
||
138 | return $this->getParameter('billingCity'); |
||
139 | } |
||
140 | |||
141 | public function setBillingState($billingState) |
||
142 | { |
||
143 | return $this->setParameter('billingState', $billingState); |
||
144 | } |
||
145 | |||
146 | public function getBillingState() |
||
147 | { |
||
148 | return $this->getParameter('billingState'); |
||
149 | } |
||
150 | |||
151 | public function setBillingZip($billingZip) |
||
152 | { |
||
153 | return $this->setParameter('billingZip', $billingZip); |
||
154 | } |
||
155 | |||
156 | public function getBillingZip() |
||
157 | { |
||
158 | return $this->getParameter('billingZip'); |
||
159 | } |
||
160 | |||
161 | public function setBillingCountry($billingCountry) |
||
162 | { |
||
163 | return $this->setParameter('billingCountry', $billingCountry); |
||
164 | } |
||
165 | |||
166 | public function getBillingCountry() |
||
167 | { |
||
168 | return $this->getParameter('billingCountry'); |
||
169 | } |
||
170 | |||
171 | public function setBillingEmail($billingEmail) |
||
174 | } |
||
175 | |||
176 | public function getBillingEmail() |
||
177 | { |
||
178 | return $this->getParameter('billingEmail'); |
||
179 | } |
||
180 | |||
181 | public function setBillingTel($billingTel) |
||
182 | { |
||
183 | return $this->setParameter('billingTel', $billingTel); |
||
184 | } |
||
185 | |||
186 | public function getBillingTel() |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Get data |
||
193 | * |
||
194 | * @access public |
||
195 | * @return array |
||
196 | */ |
||
197 | public function getData() |
||
198 | { |
||
199 | $this->validate( |
||
200 | 'merchantId', 'accessCode', 'workingKey', |
||
201 | 'amount', 'currency', 'returnUrl', 'cancelUrl' |
||
202 | ); |
||
203 | |||
204 | $data = []; |
||
205 | |||
206 | $data['merchant_id'] = $this->getMerchantId(); |
||
207 | $data['access_code'] = $this->getAccessCode(); |
||
208 | $data['amount'] = $this->getAmount(); |
||
209 | $data['currency'] = $this->getCurrency(); |
||
210 | $data['order_id'] = $this->getTransactionId(); |
||
211 | $data['redirect_url'] = $this->getReturnUrl(); |
||
212 | $data['cancel_url'] = $this->getCancelUrl(); |
||
213 | $data['merchant_param1'] = $this->getMerchantParameter1(); |
||
214 | $data['merchant_param2'] = $this->getMerchantParameter2(); |
||
215 | $data['merchant_param3'] = $this->getMerchantParameter3(); |
||
216 | $data['merchant_param4'] = $this->getMerchantParameter4(); |
||
217 | $data['merchant_param5'] = $this->getMerchantParameter5(); |
||
218 | $data['billing_name'] = $this->getBillingName(); |
||
219 | $data['billing_address'] = $this->getBillingAddress(); |
||
220 | $data['billing_city'] = $this->getBillingCity(); |
||
221 | $data['billing_state'] = $this->getBillingState(); |
||
222 | $data['billing_zip'] = $this->getBillingZip(); |
||
223 | $data['billing_country'] = $this->getBillingCountry(); |
||
224 | $data['billing_email'] = $this->getBillingEmail(); |
||
225 | $data['billing_tel'] = $this->getBillingTel(); |
||
226 | |||
227 | if ( $this->getCard() ) { |
||
228 | $data['card_number'] = $this->getCard()->getNumber(); |
||
229 | $data['expiry_month'] = $this->getCard()->getExpiryMonth(); |
||
230 | $data['expiry_year'] = $this->getCard()->getExpiryYear(); |
||
231 | $data['cvv_number'] = $this->getCard()->getCvv(); |
||
232 | } |
||
233 | |||
234 | return $data; |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Send data |
||
239 | * |
||
240 | * @param array $data Data |
||
241 | * |
||
242 | * @access public |
||
243 | * @return PurchaseResponse |
||
244 | */ |
||
245 | public function sendData($data) |
||
270 | ]); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Get endpoint |
||
275 | * |
||
276 | * Returns endpoint depending on test mode |
||
277 | * |
||
278 | * @access protected |
||
279 | * @return string |
||
280 | */ |
||
281 | protected function getEndpoint() |
||
284 | } |
||
285 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths