| Conditions | 5 |
| Paths | 42 |
| Total Lines | 69 |
| Code Lines | 43 |
| 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 |
||
| 184 | public function getVaultDetails($storeId, $numberToken, $vaultData) |
||
| 185 | { |
||
| 186 | /** @var ZendClient $client */ |
||
| 187 | $client = $this->httpClientFactory->create(); |
||
| 188 | $url = $this->configBase->getApiUrl($storeId); |
||
| 189 | $apiBearer = $this->configBase->getMerchantGatewayOauth($storeId); |
||
| 190 | |||
| 191 | $month = $vaultData['expiration_month']; |
||
| 192 | if (strlen($month) === 1) { |
||
| 193 | $month = '0'.$month; |
||
| 194 | } |
||
| 195 | |||
| 196 | $request = [ |
||
| 197 | 'number_token' => $numberToken, |
||
| 198 | 'expiration_month' => $month, |
||
| 199 | 'expiration_year' => $vaultData['expiration_year'], |
||
| 200 | 'customer_id' => $vaultData['customer_email'], |
||
| 201 | 'cardholder_name' => $vaultData['cardholder_name'], |
||
| 202 | 'verify_card' => false, |
||
| 203 | ]; |
||
| 204 | |||
| 205 | try { |
||
| 206 | $client->setUri($url.'/v1/cards'); |
||
| 207 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
| 208 | $client->setHeaders('Authorization', 'Bearer '.$apiBearer); |
||
| 209 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
| 210 | $client->setMethod(ZendClient::POST); |
||
| 211 | |||
| 212 | $responseBody = $client->request()->getBody(); |
||
| 213 | $data = $this->json->unserialize($responseBody); |
||
| 214 | |||
| 215 | if (isset($data['card_id'])) { |
||
| 216 | $response = [ |
||
| 217 | 'success' => 1, |
||
| 218 | 'card_id' => $data['card_id'], |
||
| 219 | 'number_token' => $data['number_token'], |
||
| 220 | ]; |
||
| 221 | } |
||
| 222 | |||
| 223 | if (isset($data['details'])) { |
||
| 224 | $response = [ |
||
| 225 | 'success' => 0, |
||
| 226 | 'message' => [ |
||
| 227 | 'code' => $data['details'][0]['error_code'], |
||
| 228 | 'text' => $data['details'][0]['description_detail'], |
||
| 229 | ], |
||
| 230 | ]; |
||
| 231 | } |
||
| 232 | |||
| 233 | $this->logger->debug( |
||
| 234 | [ |
||
| 235 | 'url' => $url.'v1/cards', |
||
| 236 | 'request' => $this->json->serialize($request), |
||
| 237 | 'response' => $responseBody, |
||
| 238 | ] |
||
| 239 | ); |
||
| 240 | } catch (InvalidArgumentException $e) { |
||
| 241 | $this->logger->debug( |
||
| 242 | [ |
||
| 243 | 'url' => $url.'v1/cards', |
||
| 244 | 'request' => $request, |
||
| 245 | 'response' => $responseBody, |
||
| 246 | ] |
||
| 247 | ); |
||
| 248 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 249 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
| 250 | } |
||
| 251 | |||
| 252 | return $response; |
||
| 253 | } |
||
| 255 |
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