| Conditions | 4 |
| Paths | 19 |
| Total Lines | 53 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 155 | public function getNumberToken($storeId, $cardNumber) |
||
| 156 | { |
||
| 157 | /** @var ZendClient $client */ |
||
| 158 | $client = $this->httpClientFactory->create(); |
||
| 159 | $request = ['card_number' => $cardNumber]; |
||
| 160 | $url = $this->configBase->getApiUrl($storeId); |
||
| 161 | $apiBearer = $this->configBase->getMerchantGatewayOauth($storeId); |
||
| 162 | |||
| 163 | try { |
||
| 164 | $client->setUri($url.'/v1/tokens/card'); |
||
| 165 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
| 166 | $client->setHeaders('Authorization', 'Bearer '.$apiBearer); |
||
| 167 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
| 168 | $client->setMethod(ZendClient::POST); |
||
| 169 | |||
| 170 | $responseBody = $client->request()->getBody(); |
||
| 171 | $data = $this->json->unserialize($responseBody); |
||
| 172 | $response = [ |
||
| 173 | 'success' => 0, |
||
| 174 | ]; |
||
| 175 | if (!empty($data['number_token'])) { |
||
| 176 | $response = [ |
||
| 177 | 'success' => 1, |
||
| 178 | 'number_token' => $data['number_token'], |
||
| 179 | ]; |
||
| 180 | } |
||
| 181 | $this->logger->debug( |
||
| 182 | [ |
||
| 183 | 'url' => $url.'v1/tokens/card', |
||
| 184 | 'response' => $responseBody, |
||
| 185 | ] |
||
| 186 | ); |
||
| 187 | |||
| 188 | if (!$client->request()->isSuccessful()) { |
||
| 189 | $response = [ |
||
| 190 | 'success' => 0, |
||
| 191 | 'message' => [ |
||
| 192 | 'text' => __('Error creating payment. Please, contact the store owner or try again.'), |
||
| 193 | ], |
||
| 194 | ]; |
||
| 195 | } |
||
| 196 | } catch (\InvalidArgumentException $e) { |
||
| 197 | $this->logger->debug( |
||
| 198 | [ |
||
| 199 | 'url' => $url.'v1/tokens/card', |
||
| 200 | 'response' => $responseBody, |
||
| 201 | ] |
||
| 202 | ); |
||
| 203 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
| 204 | throw new \Exception('Invalid JSON was returned by the gateway'); |
||
| 205 | } |
||
| 206 | |||
| 207 | return $response; |
||
| 208 | } |
||
| 210 |
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