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