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