| Conditions | 6 |
| Paths | 27 |
| Total Lines | 71 |
| Code Lines | 41 |
| 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 |
||
| 90 | public function placeRequest(TransferInterface $transferObject) |
||
| 91 | { |
||
| 92 | /** @var ZendClient $client */ |
||
| 93 | $isSuccess = false; |
||
| 94 | $client = $this->httpClientFactory->create(); |
||
| 95 | $request = $transferObject->getBody(); |
||
| 96 | $storeId = $request[self::STORE_ID]; |
||
| 97 | $url = $this->config->getApiUrl($storeId); |
||
| 98 | $apiBearer = $this->config->getMerchantGatewayOauth($storeId); |
||
| 99 | unset($request[self::STORE_ID]); |
||
| 100 | |||
| 101 | try { |
||
| 102 | $client->setUri($url.'v1/payments/combined'); |
||
| 103 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
| 104 | $client->setHeaders( |
||
| 105 | [ |
||
| 106 | 'Authorization' => 'Bearer '.$apiBearer, |
||
| 107 | 'x-transaction-channel-entry' => 'MG', |
||
| 108 | ] |
||
| 109 | ); |
||
| 110 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
| 111 | $client->setMethod(ZendClient::POST); |
||
| 112 | |||
| 113 | $responseBody = $client->request()->getBody(); |
||
| 114 | $data = $this->json->unserialize($responseBody); |
||
| 115 | $response = array_merge( |
||
| 116 | [ |
||
| 117 | self::RESULT_CODE => 0, |
||
| 118 | ], |
||
| 119 | $data |
||
| 120 | ); |
||
| 121 | |||
| 122 | if (isset($data['payments'])) { |
||
| 123 | foreach ($data['payments'] as $payment) { |
||
| 124 | if (isset($payment['payment_id'])) { |
||
| 125 | $isSuccess = true; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($isSuccess) { |
||
| 131 | $response = array_merge( |
||
| 132 | [ |
||
| 133 | self::RESULT_CODE => 1, |
||
| 134 | self::EXT_ORD_ID => $data['combined_id'], |
||
| 135 | ], |
||
| 136 | $data |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | |||
| 140 | $this->logger->debug( |
||
| 141 | [ |
||
| 142 | 'url' => $url.'v1/payments/combined', |
||
| 143 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 144 | 'response' => $responseBody, |
||
| 145 | ] |
||
| 146 | ); |
||
| 147 | } catch (InvalidArgumentException $e) { |
||
| 148 | $this->logger->debug( |
||
| 149 | [ |
||
| 150 | 'exception' => $e->getMessage(), |
||
| 151 | 'url' => $url.'v1/payments/combined', |
||
| 152 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
| 153 | 'response' => $responseBody, |
||
| 154 | ] |
||
| 155 | ); |
||
| 156 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 157 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
| 158 | } |
||
| 159 | |||
| 160 | return $response; |
||
| 161 | } |
||
| 163 |
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