| Conditions | 3 |
| Paths | 14 |
| Total Lines | 57 |
| Code Lines | 34 |
| 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 |
||
| 74 | public function placeRequest(TransferInterface $transferObject) |
||
| 75 | { |
||
| 76 | $client = $this->httpClientFactory->create(); |
||
| 77 | $request = $transferObject->getBody(); |
||
| 78 | |||
| 79 | $url = $this->config->getApiUrl(); |
||
| 80 | $apiBearer = $this->config->getMerchantGatewayOauth(); |
||
| 81 | $orderMoip = $request[self::MOIP_ORDER_ID]; |
||
| 82 | |||
| 83 | try { |
||
| 84 | $client->setUri($url.'orders/'.$orderMoip.'/refunds'); |
||
| 85 | $client->setConfig(['maxredirects' => 0, 'timeout' => 120]); |
||
| 86 | $client->setHeaders('Authorization', 'Bearer '.$apiBearer); |
||
| 87 | $client->setRawData($this->json->serialize($request['send']), 'application/json'); |
||
| 88 | $client->setMethod(ZendClient::POST); |
||
| 89 | |||
| 90 | $responseBody = $client->request()->getBody(); |
||
| 91 | |||
| 92 | $data = $this->json->unserialize($responseBody); |
||
| 93 | |||
| 94 | if (isset($data['id'])) { |
||
| 95 | $response = array_merge( |
||
| 96 | [ |
||
| 97 | 'RESULT_CODE' => 1, |
||
| 98 | 'STATUS' => $data['status'], |
||
| 99 | 'REFUND_ID' => $data['id'], |
||
| 100 | ], |
||
| 101 | $data |
||
| 102 | ); |
||
| 103 | } else { |
||
| 104 | $response = array_merge( |
||
| 105 | [ |
||
| 106 | 'RESULT_CODE' => 0, |
||
| 107 | ], |
||
| 108 | $data |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | $this->logger->debug( |
||
| 112 | [ |
||
| 113 | 'url' => $url.'orders/'.$orderMoip.'/refunds', |
||
| 114 | 'request' => $this->json->serialize($request['send']), |
||
| 115 | 'response' => $responseBody, |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | } catch (InvalidArgumentException $e) { |
||
| 119 | $this->logger->debug( |
||
| 120 | [ |
||
| 121 | 'url' => $url.'orders/'.$orderMoip.'/refunds', |
||
| 122 | 'request' => $this->json->serialize($request['send']), |
||
| 123 | 'response' => $responseBody, |
||
| 124 | ] |
||
| 125 | ); |
||
| 126 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 127 | throw new \Exception('Invalid JSON was returned by the gateway'); |
||
| 128 | } |
||
| 129 | |||
| 130 | return $response; |
||
| 131 | } |
||
| 133 |
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