Total Complexity | 42 |
Total Lines | 274 |
Duplicated Lines | 0 % |
Changes | 3 | ||
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 |
||
12 | class PurchaseRequest extends AbstractRequest { |
||
13 | |||
14 | const EP_HOST_TEST = 'https://spayuattrns.bmtest.om/transaction.do?command=initiateTransaction'; |
||
15 | const EP_HOST_LIVE = 'https://smartpaytrns.bankmuscat.com/transaction.do?command=initiateTransaction'; |
||
16 | |||
17 | public function initialize(array $parameters = []) |
||
18 | { |
||
19 | return parent::initialize($parameters); |
||
20 | } |
||
21 | |||
22 | public function getMerchantId() |
||
23 | { |
||
24 | return $this->getParameter('merchantId'); |
||
25 | } |
||
26 | |||
27 | public function setMerchantId($merchantId) |
||
28 | { |
||
29 | return $this->setParameter('merchantId', $merchantId); |
||
30 | } |
||
31 | |||
32 | public function getAccessCode() |
||
33 | { |
||
34 | return $this->getParameter('accessCode'); |
||
35 | } |
||
36 | |||
37 | public function setAccessCode($accessCode) |
||
38 | { |
||
39 | return $this->setParameter('accessCode', $accessCode); |
||
40 | } |
||
41 | |||
42 | public function getWorkingKey() |
||
43 | { |
||
44 | return $this->getParameter('workingKey'); |
||
45 | } |
||
46 | |||
47 | public function setWorkingKey($workingKey) |
||
48 | { |
||
49 | return $this->setParameter('workingKey', $workingKey); |
||
50 | } |
||
51 | |||
52 | public function getOrderId() |
||
53 | { |
||
54 | return $this->getParameter('orderId'); |
||
55 | } |
||
56 | |||
57 | public function setOrderId($orderId) |
||
58 | { |
||
59 | return $this->setParameter('orderId', $orderId); |
||
60 | } |
||
61 | |||
62 | public function getMerchantParameter1() |
||
63 | { |
||
64 | return $this->getParameter('merchantParameter1'); |
||
65 | } |
||
66 | |||
67 | public function setMerchantParameter1($parameter) |
||
68 | { |
||
69 | return $this->setParameter('merchantParameter1', $parameter); |
||
70 | } |
||
71 | |||
72 | public function getMerchantParameter2() |
||
75 | } |
||
76 | |||
77 | public function setMerchantParameter2($parameter) |
||
78 | { |
||
79 | return $this->setParameter('merchantParameter2', $parameter); |
||
80 | } |
||
81 | |||
82 | public function getMerchantParameter3() |
||
83 | { |
||
84 | return $this->getParameter('merchantParameter3'); |
||
85 | } |
||
86 | |||
87 | public function setMerchantParameter3($parameter) |
||
88 | { |
||
89 | return $this->setParameter('merchantParameter3', $parameter); |
||
90 | } |
||
91 | |||
92 | public function getMerchantParameter4() |
||
93 | { |
||
94 | return $this->getParameter('merchantParameter4'); |
||
95 | } |
||
96 | |||
97 | public function setMerchantParameter4($parameter) |
||
98 | { |
||
99 | return $this->setParameter('merchantParameter4', $parameter); |
||
100 | } |
||
101 | |||
102 | public function getMerchantParameter5() |
||
105 | } |
||
106 | |||
107 | public function setMerchantParameter5($parameter) |
||
108 | { |
||
109 | return $this->setParameter('merchantParameter5', $parameter); |
||
110 | } |
||
111 | |||
112 | public function setBillingName($billingName) |
||
113 | { |
||
114 | return $this->setParameter('billingName', $billingName); |
||
115 | } |
||
116 | |||
117 | public function getBillingName() |
||
118 | { |
||
119 | return $this->getParameter('billingName'); |
||
120 | } |
||
121 | |||
122 | public function setBillingAddress($billingAddress) |
||
123 | { |
||
124 | return $this->setParameter('billingAddress', $billingAddress); |
||
125 | } |
||
126 | |||
127 | public function getBillingAddress() |
||
130 | } |
||
131 | |||
132 | public function setBillingCity($billingCity) |
||
133 | { |
||
134 | return $this->setParameter('billingCity', $billingCity); |
||
135 | } |
||
136 | |||
137 | public function getBillingCity() |
||
138 | { |
||
139 | return $this->getParameter('billingCity'); |
||
140 | } |
||
141 | |||
142 | public function setBillingState($billingState) |
||
143 | { |
||
144 | return $this->setParameter('billingState', $billingState); |
||
145 | } |
||
146 | |||
147 | public function getBillingState() |
||
148 | { |
||
149 | return $this->getParameter('billingState'); |
||
150 | } |
||
151 | |||
152 | public function setBillingZip($billingZip) |
||
153 | { |
||
154 | return $this->setParameter('billingZip', $billingZip); |
||
155 | } |
||
156 | |||
157 | public function getBillingZip() |
||
158 | { |
||
159 | return $this->getParameter('billingZip'); |
||
160 | } |
||
161 | |||
162 | public function setBillingCountry($billingCountry) |
||
163 | { |
||
164 | return $this->setParameter('billingCountry', $billingCountry); |
||
165 | } |
||
166 | |||
167 | public function getBillingCountry() |
||
168 | { |
||
169 | return $this->getParameter('billingCountry'); |
||
170 | } |
||
171 | |||
172 | public function setBillingEmail($billingEmail) |
||
175 | } |
||
176 | |||
177 | public function getBillingEmail() |
||
178 | { |
||
179 | return $this->getParameter('billingEmail'); |
||
180 | } |
||
181 | |||
182 | public function setBillingTel($billingTel) |
||
183 | { |
||
184 | return $this->setParameter('billingTel', $billingTel); |
||
185 | } |
||
186 | |||
187 | public function getBillingTel() |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Get data |
||
194 | * |
||
195 | * @access public |
||
196 | * @return array |
||
197 | */ |
||
198 | public function getData() |
||
199 | { |
||
200 | $this->validate( |
||
201 | 'merchantId', 'accessCode', 'workingKey', |
||
202 | 'amount', 'currency', 'returnUrl', 'cancelUrl' |
||
203 | ); |
||
204 | |||
205 | $data = []; |
||
206 | |||
207 | $data['merchant_id'] = $this->getMerchantId(); |
||
208 | $data['access_code'] = $this->getAccessCode(); |
||
209 | $data['amount'] = $this->getAmount(); |
||
210 | $data['currency'] = $this->getCurrency(); |
||
211 | $data['order_id'] = $this->getTransactionId(); |
||
212 | $data['redirect_url'] = $this->getReturnUrl(); |
||
213 | $data['cancel_url'] = $this->getCancelUrl(); |
||
214 | $data['merchant_param1'] = $this->getMerchantParameter1(); |
||
215 | $data['merchant_param2'] = $this->getMerchantParameter2(); |
||
216 | $data['merchant_param3'] = $this->getMerchantParameter3(); |
||
217 | $data['merchant_param4'] = $this->getMerchantParameter4(); |
||
218 | $data['merchant_param5'] = $this->getMerchantParameter5(); |
||
219 | $data['billing_name'] = $this->getBillingName(); |
||
220 | $data['billing_address'] = $this->getBillingAddress(); |
||
221 | $data['billing_city'] = $this->getBillingCity(); |
||
222 | $data['billing_state'] = $this->getBillingState(); |
||
223 | $data['billing_zip'] = $this->getBillingZip(); |
||
224 | $data['billing_country'] = $this->getBillingCountry(); |
||
225 | $data['billing_email'] = $this->getBillingEmail(); |
||
226 | $data['billing_tel'] = $this->getBillingTel(); |
||
227 | $data['customer_email'] = '[email protected]'; |
||
228 | |||
229 | if ( $this->getCard() ) { |
||
230 | $data['card_number'] = $this->getCard()->getNumber(); |
||
231 | $data['expiry_month'] = $this->getCard()->getExpiryMonth(); |
||
232 | $data['expiry_year'] = $this->getCard()->getExpiryYear(); |
||
233 | $data['cvv_number'] = $this->getCard()->getCvv(); |
||
234 | } |
||
235 | |||
236 | return $data; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Send data |
||
241 | * |
||
242 | * @param array $data Data |
||
243 | * |
||
244 | * @access public |
||
245 | * @return PurchaseResponse |
||
246 | */ |
||
247 | public function sendData($data) |
||
272 | ]); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Get endpoint |
||
277 | * |
||
278 | * Returns endpoint depending on test mode |
||
279 | * |
||
280 | * @access protected |
||
281 | * @return string |
||
282 | */ |
||
283 | protected function getEndpoint() |
||
286 | } |
||
287 | } |
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