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