| Conditions | 3 |
| Paths | 14 |
| Total Lines | 57 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 85 | public function placeRequest(TransferInterface $transferObject) |
||
| 86 | { |
||
| 87 | /** @var ZendClient $client */ |
||
| 88 | $client = $this->httpClientFactory->create(); |
||
| 89 | $request = $transferObject->getBody(); |
||
| 90 | $url = $this->config->getApiUrl(); |
||
| 91 | $apiBearer = $this->config->getMerchantGatewayOauth(); |
||
| 92 | |||
| 93 | try { |
||
| 94 | $client->setUri($url.'/v1/payments/combined/cancel'); |
||
| 95 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
| 96 | $client->setHeaders( |
||
| 97 | [ |
||
| 98 | 'Authorization' => 'Bearer '.$apiBearer, |
||
| 99 | ] |
||
| 100 | ); |
||
| 101 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
| 102 | $client->setMethod(ZendClient::POST); |
||
| 103 | |||
| 104 | $responseBody = $client->request()->getBody(); |
||
| 105 | $data = $this->json->unserialize($responseBody); |
||
| 106 | $response = array_merge( |
||
| 107 | [ |
||
| 108 | self::RESULT_CODE => 0, |
||
| 109 | ], |
||
| 110 | $data |
||
| 111 | ); |
||
| 112 | if (isset($data[self::RESPONSE_PAYMENTS])) { |
||
| 113 | $response = array_merge( |
||
| 114 | [ |
||
| 115 | self::RESULT_CODE => 1, |
||
| 116 | ], |
||
| 117 | $data |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | $this->logger->debug( |
||
| 121 | [ |
||
| 122 | 'url' => $url.'v1/payments/combined/cancel', |
||
| 123 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 124 | 'response' => $this->json->serialize($response), |
||
| 125 | ] |
||
| 126 | ); |
||
| 127 | } catch (InvalidArgumentException $e) { |
||
| 128 | $this->logger->debug( |
||
| 129 | [ |
||
| 130 | 'oauth' => $apiBearer, |
||
| 131 | 'url' => $url.'v1/payments/combined/cancel', |
||
| 132 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 133 | 'response' => $this->json->serialize($response), |
||
| 134 | 'error' => $e->getMessage(), |
||
| 135 | ] |
||
| 136 | ); |
||
| 137 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 138 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
| 139 | } |
||
| 140 | |||
| 141 | return $response; |
||
| 142 | } |
||
| 144 |
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