| Conditions | 4 |
| Paths | 18 |
| Total Lines | 70 |
| Code Lines | 42 |
| 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 |
||
| 100 | public function placeRequest(TransferInterface $transferObject) |
||
| 101 | { |
||
| 102 | /** @var ZendClient $client */ |
||
| 103 | $client = $this->httpClientFactory->create(); |
||
| 104 | $request = $transferObject->getBody(); |
||
| 105 | $storeId = $request[self::STORE_ID]; |
||
| 106 | $url = $this->config->getApiUrl($storeId); |
||
| 107 | $apiBearer = $this->config->getMerchantGatewayOauth($storeId); |
||
| 108 | unset($request[self::STORE_ID]); |
||
| 109 | |||
| 110 | try { |
||
| 111 | $client->setUri($url.'/v1/payments/cancel/request'); |
||
| 112 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
| 113 | $client->setHeaders( |
||
| 114 | [ |
||
| 115 | 'Authorization' => 'Bearer '.$apiBearer, |
||
| 116 | 'x-transaction-channel-entry' => 'MG', |
||
| 117 | ] |
||
| 118 | ); |
||
| 119 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
| 120 | $client->setMethod(ZendClient::POST); |
||
| 121 | |||
| 122 | $responseBody = $client->request()->getBody(); |
||
| 123 | $data = $this->json->unserialize($responseBody); |
||
| 124 | $response = array_merge( |
||
| 125 | [ |
||
| 126 | self::RESULT_CODE => 0, |
||
| 127 | ], |
||
| 128 | $data |
||
| 129 | ); |
||
| 130 | if (isset($data[self::RESPONSE_CANCEL_REQUEST_ID])) { |
||
| 131 | $response = array_merge( |
||
| 132 | [ |
||
| 133 | self::RESULT_CODE => 1, |
||
| 134 | self::RESPONSE_CANCEL_REQUEST_ID => $data[self::RESPONSE_CANCEL_REQUEST_ID], |
||
| 135 | ], |
||
| 136 | $data |
||
| 137 | ); |
||
| 138 | if ($data[self::RESPONSE_STATUS] === self::RESPONSE_STATUS_DENIED) { |
||
| 139 | $response = array_merge( |
||
| 140 | [ |
||
| 141 | self::RESULT_CODE => 0, |
||
| 142 | self::RESPONSE_CANCEL_REQUEST_ID => $data[self::RESPONSE_CANCEL_REQUEST_ID], |
||
| 143 | ], |
||
| 144 | $data |
||
| 145 | ); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | $this->logger->debug( |
||
| 149 | [ |
||
| 150 | 'url' => $url.'v1/payments/cancel/request', |
||
| 151 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 152 | 'response' => $this->json->serialize($response), |
||
| 153 | ] |
||
| 154 | ); |
||
| 155 | } catch (InvalidArgumentException $e) { |
||
| 156 | $this->logger->debug( |
||
| 157 | [ |
||
| 158 | 'oauth' => $apiBearer, |
||
| 159 | 'url' => $url.'v1/payments/cancel/request', |
||
| 160 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 161 | 'response' => $this->json->serialize($response), |
||
| 162 | 'error' => $e->getMessage(), |
||
| 163 | ] |
||
| 164 | ); |
||
| 165 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 166 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
| 167 | } |
||
| 168 | |||
| 169 | return $response; |
||
| 170 | } |
||
| 172 |
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