Conditions | 10 |
Paths | 22 |
Total Lines | 38 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
41 | public function __construct(RequestInterface $request, $data) |
||
42 | { |
||
43 | parent::__construct($request, $data); |
||
44 | |||
45 | $security = new Security(); |
||
46 | |||
47 | try { |
||
48 | $this->redsysMessages = (new Factory(new CatalogLoader()))->createCatalogByLanguage(array_key_exists('language', $this->request->getParameters()) ? $this->request->getParameters()['language'] : 'en'); |
||
49 | } catch (CatalogNotFoundException $e) { |
||
50 | $this->redsysMessages = (new Factory(new CatalogLoader()))->createCatalogByLanguage('en'); |
||
51 | } |
||
52 | |||
53 | if (!empty($data['Ds_MerchantParameters'])) { |
||
54 | $this->merchantParameters = $security->decodeMerchantParameters($data['Ds_MerchantParameters']); |
||
55 | } elseif (!empty($data['DS_MERCHANTPARAMETERS'])) { |
||
56 | $this->merchantParameters = $security->decodeMerchantParameters($data['DS_MERCHANTPARAMETERS']); |
||
57 | $this->usingUpcaseResponse = true; |
||
58 | } else { |
||
59 | throw new InvalidResponseException('Invalid response from payment gateway (no data)'); |
||
60 | } |
||
61 | |||
62 | if (!empty($this->merchantParameters['Ds_Order'])) { |
||
63 | $order = $this->merchantParameters['Ds_Order']; |
||
64 | } elseif (!empty($this->merchantParameters['DS_ORDER'])) { |
||
65 | $order = $this->merchantParameters['DS_ORDER']; |
||
66 | $this->usingUpcaseParameters = true; |
||
67 | } else { |
||
68 | throw new InvalidResponseException(); |
||
69 | } |
||
70 | |||
71 | $this->returnSignature = $security->createReturnSignature( |
||
72 | $data[$this->usingUpcaseResponse ? 'DS_MERCHANTPARAMETERS' : 'Ds_MerchantParameters'], |
||
73 | $order, |
||
74 | $this->request->getHmacKey() |
||
|
|||
75 | ); |
||
76 | |||
77 | if ($this->returnSignature != $data[$this->usingUpcaseResponse ? 'DS_SIGNATURE' : 'Ds_Signature']) { |
||
78 | throw new InvalidResponseException('Invalid response from payment gateway (signature mismatch)'); |
||
79 | } |
||
177 |