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