Conditions | 3 |
Paths | 14 |
Total Lines | 54 |
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 |
||
85 | public function placeRequest(TransferInterface $transferObject) |
||
86 | { |
||
87 | /** @var ZendClient $client */ |
||
88 | $client = $this->httpClientFactory->create(); |
||
89 | $request = $transferObject->getBody(); |
||
90 | $url = $this->config->getApiUrl(); |
||
91 | $apiBearer = $this->config->getMerchantGatewayOauth(); |
||
92 | |||
93 | try { |
||
94 | $client->setUri($url.'/v1/payment-links'); |
||
95 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
96 | $client->setHeaders('Authorization', 'Bearer '.$apiBearer); |
||
97 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
98 | $client->setMethod(ZendClient::POST); |
||
99 | |||
100 | $responseBody = $client->request()->getBody(); |
||
101 | $data = $this->json->unserialize($responseBody); |
||
102 | if (isset($data['link_id'])) { |
||
103 | $response = array_merge( |
||
104 | [ |
||
105 | self::RESULT_CODE => 1, |
||
106 | self::EXT_ORD_ID => $data['link_id'], |
||
107 | ], |
||
108 | $data |
||
109 | ); |
||
110 | } else { |
||
111 | $response = array_merge( |
||
112 | [ |
||
113 | self::RESULT_CODE => 0, |
||
114 | ], |
||
115 | $data |
||
116 | ); |
||
117 | } |
||
118 | $this->logger->debug( |
||
119 | [ |
||
120 | 'url' => $url.'v1/payment-links', |
||
121 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
122 | 'response' => $responseBody, |
||
123 | ] |
||
124 | ); |
||
125 | } catch (InvalidArgumentException $e) { |
||
126 | $this->logger->debug( |
||
127 | [ |
||
128 | 'url' => $url.'v1/payment-links', |
||
129 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
130 | 'response' => $responseBody, |
||
131 | 'error' => $e->getMessage(), |
||
132 | ] |
||
133 | ); |
||
134 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
135 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
136 | } |
||
137 | |||
138 | return $response; |
||
139 | } |
||
141 |
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