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