Conditions | 1 |
Paths | 1 |
Total Lines | 237 |
Code Lines | 154 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
133 | public function providerProcess(): iterable |
||
134 | { |
||
135 | yield 'normal' => [ |
||
136 | [ |
||
137 | 'uppTransactionId' => '123456789012345678', |
||
138 | 'status' => 'success', |
||
139 | 'refno' => '16001', |
||
140 | 'amount' => '1000', |
||
141 | 'currency' => 'CHF', |
||
142 | 'responseMessage' => 'Payment was successful', |
||
143 | 'sign' => 'c0a817ad85a2bc830f8fd9d4f1cd0f3a2a8757239f98ec1700a182e7f182c6a7', |
||
144 | ], |
||
145 | [ |
||
146 | 'message' => [ |
||
147 | 'status' => 'success', |
||
148 | 'message' => 'Payment was successful', |
||
149 | ], |
||
150 | ], |
||
151 | false, |
||
152 | ]; |
||
153 | yield 'invalid HMAC signature' => [ |
||
154 | [ |
||
155 | 'uppTransactionId' => '123456789012345678', |
||
156 | 'status' => 'success', |
||
157 | 'refno' => '16001', |
||
158 | 'amount' => '1000', |
||
159 | 'currency' => 'CHF', |
||
160 | 'responseMessage' => 'Payment was successful', |
||
161 | 'sign' => 'a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0', |
||
162 | ], |
||
163 | [ |
||
164 | 'message' => [ |
||
165 | 'status' => 'error', |
||
166 | 'message' => 'Invalid HMAC signature', |
||
167 | ], |
||
168 | ], |
||
169 | false, |
||
170 | ]; |
||
171 | yield 'missing HMAC signature' => [ |
||
172 | [ |
||
173 | 'uppTransactionId' => '123456789012345678', |
||
174 | 'status' => 'success', |
||
175 | 'refno' => '16001', |
||
176 | 'amount' => '1000', |
||
177 | 'currency' => 'CHF', |
||
178 | 'responseMessage' => 'Payment was successful', |
||
179 | ], |
||
180 | [ |
||
181 | 'message' => [ |
||
182 | 'status' => 'error', |
||
183 | 'message' => 'Missing HMAC signature', |
||
184 | ], |
||
185 | ], |
||
186 | false, |
||
187 | ]; |
||
188 | yield 'error' => [ |
||
189 | [ |
||
190 | 'uppTransactionId' => '876543210987654321', |
||
191 | 'status' => 'error', |
||
192 | 'refno' => '16001', |
||
193 | 'errorMessage' => 'Dear Sir/Madam, Fire! fire! help me! All the best, Maurice Moss.', |
||
194 | 'sign' => '8015e6fef2caf41bb11cd2f54077bedb6339bd1aecf418091f77662ee13f81eb', |
||
195 | ], |
||
196 | [ |
||
197 | 'message' => [ |
||
198 | 'status' => 'error', |
||
199 | 'message' => 'Dear Sir/Madam, Fire! fire! help me! All the best, Maurice Moss.', |
||
200 | ], |
||
201 | ], |
||
202 | false, |
||
203 | ]; |
||
204 | yield 'cancel' => [ |
||
205 | [ |
||
206 | 'uppTransactionId' => '876543210987654321', |
||
207 | 'status' => 'cancel', |
||
208 | 'refno' => '16001', |
||
209 | 'sign' => '8015e6fef2caf41bb11cd2f54077bedb6339bd1aecf418091f77662ee13f81eb', |
||
210 | ], |
||
211 | [ |
||
212 | 'message' => [ |
||
213 | 'status' => 'cancel', |
||
214 | 'message' => 'Cancelled', |
||
215 | ], |
||
216 | ], |
||
217 | false, |
||
218 | ]; |
||
219 | yield 'invalid body' => [ |
||
220 | null, |
||
221 | [ |
||
222 | 'message' => [ |
||
223 | 'status' => 'error', |
||
224 | 'message' => 'Parsed body is expected to be an array but got: NULL', |
||
225 | ], |
||
226 | ], |
||
227 | false, |
||
228 | ]; |
||
229 | yield 'invalid status' => [ |
||
230 | [ |
||
231 | 'uppTransactionId' => '123456789012345678', |
||
232 | 'status' => 'non-existing-status', |
||
233 | 'refno' => '16001', |
||
234 | 'amount' => '10000', |
||
235 | 'currency' => 'CHF', |
||
236 | 'responseMessage' => 'Payment was successful', |
||
237 | 'sign' => '811cb0cd3333311a242adb9907052b74d1c462fb94b071ef4d8790faa7f7fd72', |
||
238 | ], |
||
239 | [ |
||
240 | 'message' => [ |
||
241 | 'status' => 'error', |
||
242 | 'message' => 'Unsupported status in Datatrans data: non-existing-status', |
||
243 | ], |
||
244 | ], |
||
245 | false, |
||
246 | ]; |
||
247 | yield 'non-existing order' => [ |
||
248 | [ |
||
249 | 'uppTransactionId' => '123456789012345678', |
||
250 | 'status' => 'success', |
||
251 | 'amount' => '10000', |
||
252 | 'currency' => 'CHF', |
||
253 | 'responseMessage' => 'Payment was successful', |
||
254 | 'sign' => 'd7f9a1716b1538e2cd8f239230526435bc0dcf289a1769f7426badcbaa0efbc8', |
||
255 | ], |
||
256 | [ |
||
257 | 'message' => [ |
||
258 | 'status' => 'error', |
||
259 | 'message' => 'Cannot validate an order without a valid order ID', |
||
260 | ], |
||
261 | ], |
||
262 | false, |
||
263 | ]; |
||
264 | yield 'non-existing amount' => [ |
||
265 | [ |
||
266 | 'uppTransactionId' => '123456789012345678', |
||
267 | 'status' => 'success', |
||
268 | 'refno' => '16001', |
||
269 | 'currency' => 'CHF', |
||
270 | 'responseMessage' => 'Payment was successful', |
||
271 | 'sign' => 'd3f6f15797038879787e6d79e8041a7e9a9cb5cd1d7c5dabdd62ac8d3052db34', |
||
272 | ], |
||
273 | [ |
||
274 | 'message' => [ |
||
275 | 'status' => 'error', |
||
276 | 'message' => 'Cannot validate an order without an amount', |
||
277 | ], |
||
278 | ], |
||
279 | false, |
||
280 | ]; |
||
281 | yield 'invalid currency' => [ |
||
282 | [ |
||
283 | 'uppTransactionId' => '123456789012345678', |
||
284 | 'status' => 'success', |
||
285 | 'refno' => '16001', |
||
286 | 'amount' => '10000', |
||
287 | 'currency' => 'USD', |
||
288 | 'responseMessage' => 'Payment was successful', |
||
289 | 'sign' => '8583b8d14fb4efa85d905ad8646074ce3ce1abe16464299e116e4cb68dd44752', |
||
290 | ], |
||
291 | [ |
||
292 | 'message' => [ |
||
293 | 'status' => 'error', |
||
294 | 'message' => 'Can only accept payment in CHF or EUR, but got: USD', |
||
295 | ], |
||
296 | ], |
||
297 | false, |
||
298 | ]; |
||
299 | yield 'incorrect amount' => [ |
||
300 | [ |
||
301 | 'uppTransactionId' => '123456789012345678', |
||
302 | 'status' => 'success', |
||
303 | 'refno' => '16001', |
||
304 | 'amount' => '1111', |
||
305 | 'currency' => 'CHF', |
||
306 | 'responseMessage' => 'Payment was successful', |
||
307 | 'sign' => '2f2bb61733d8b95101c8c938290acf0efb17daf359266262d73b67165c3ce30b', |
||
308 | ], |
||
309 | [ |
||
310 | 'message' => [ |
||
311 | 'status' => 'error', |
||
312 | 'message' => 'Cannot validate an order with incorrect balance. Expected 10.00 CHF, or 0.00 EUR, but got: 11.11 CHF', |
||
313 | ], |
||
314 | ], |
||
315 | false, |
||
316 | ]; |
||
317 | yield 'incorrect payment method' => [ |
||
318 | [ |
||
319 | 'uppTransactionId' => '123456789012345678', |
||
320 | 'status' => 'success', |
||
321 | 'refno' => '16003', |
||
322 | 'amount' => '10000', |
||
323 | 'currency' => 'CHF', |
||
324 | 'responseMessage' => 'Payment was successful', |
||
325 | 'sign' => '3111e1c3e63a77a13d9ae067690d52523c00c992b7aba262ab41de7f6e81bdad', |
||
326 | ], |
||
327 | [ |
||
328 | 'message' => [ |
||
329 | 'status' => 'error', |
||
330 | 'message' => 'Cannot validate an order whose payment method is: ebanking', |
||
331 | ], |
||
332 | ], |
||
333 | false, |
||
334 | ]; |
||
335 | yield 'incorrect status' => [ |
||
336 | [ |
||
337 | 'uppTransactionId' => '123456789012345678', |
||
338 | 'status' => 'success', |
||
339 | 'refno' => '16002', |
||
340 | 'amount' => '10000', |
||
341 | 'currency' => 'CHF', |
||
342 | 'responseMessage' => 'Payment was successful', |
||
343 | 'sign' => 'f19af94a1cafd91e8da390308e2d4a1f8bfc4ac1e2e18cf2963e1de63cec37f8', |
||
344 | ], |
||
345 | [ |
||
346 | 'message' => [ |
||
347 | 'status' => 'error', |
||
348 | 'message' => 'Cannot validate an order which is already validated', |
||
349 | ], |
||
350 | ], |
||
351 | false, |
||
352 | ]; |
||
353 | yield 'validating numeric subscription will give webTemporaryAccess' => [ |
||
354 | [ |
||
355 | 'uppTransactionId' => '123456789012345678', |
||
356 | 'status' => 'success', |
||
357 | 'refno' => '16004', |
||
358 | 'amount' => '8000', |
||
359 | 'currency' => 'CHF', |
||
360 | 'responseMessage' => 'Payment was successful', |
||
361 | 'sign' => 'a54523b461058df8d61cdbe2328bcd161bae411ec9e6206bbf4da773e3c88493', |
||
362 | ], |
||
363 | [ |
||
364 | 'message' => [ |
||
365 | 'status' => 'success', |
||
366 | 'message' => 'Payment was successful', |
||
367 | ], |
||
368 | ], |
||
369 | true, |
||
370 | ]; |
||
373 |