Conditions | 3 |
Paths | 14 |
Total Lines | 61 |
Code Lines | 37 |
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 |
||
90 | public function placeRequest(TransferInterface $transferObject) |
||
91 | { |
||
92 | /** @var ZendClient $client */ |
||
93 | $client = $this->httpClientFactory->create(); |
||
94 | $request = $transferObject->getBody(); |
||
95 | $storeId = $request[self::STORE_ID]; |
||
96 | $url = $this->config->getApiUrl($storeId); |
||
97 | $apiBearer = $this->config->getMerchantGatewayOauth($storeId); |
||
98 | unset($request[self::STORE_ID]); |
||
99 | |||
100 | try { |
||
101 | $client->setUri($url.'/v1/payments/credit'); |
||
102 | $client->setConfig(['maxredirects' => 0, 'timeout' => 45000]); |
||
103 | $client->setHeaders( |
||
104 | [ |
||
105 | 'Authorization' => 'Bearer '.$apiBearer, |
||
106 | 'x-transaction-channel-entry' => 'MG', |
||
107 | ] |
||
108 | ); |
||
109 | $client->setRawData($this->json->serialize($request), 'application/json'); |
||
110 | $client->setMethod(ZendClient::POST); |
||
111 | |||
112 | $responseBody = $client->request()->getBody(); |
||
113 | $data = $this->json->unserialize($responseBody); |
||
114 | $response = array_merge( |
||
115 | [ |
||
116 | self::RESULT_CODE => 0, |
||
117 | ], |
||
118 | $data |
||
119 | ); |
||
120 | if (isset($data['payment_id'])) { |
||
121 | $response = array_merge( |
||
122 | [ |
||
123 | self::RESULT_CODE => 1, |
||
124 | self::EXT_ORD_ID => $data['payment_id'], |
||
125 | ], |
||
126 | $data |
||
127 | ); |
||
128 | } |
||
129 | $this->logger->debug( |
||
130 | [ |
||
131 | 'url' => $url.'v1/payments/credit', |
||
132 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
133 | 'response' => $responseBody, |
||
134 | ] |
||
135 | ); |
||
136 | } catch (InvalidArgumentException $e) { |
||
137 | $this->logger->debug( |
||
138 | [ |
||
139 | 'exception' => $e->getMessage(), |
||
140 | 'oauth' => $apiBearer, |
||
141 | 'url' => $url.'v1/payments/credit', |
||
142 | 'request' => $this->json->serialize($transferObject->getBody()), |
||
143 | 'response' => $responseBody, |
||
144 | ] |
||
145 | ); |
||
146 | // phpcs:ignore Magento2.Exceptions.DirectThrow |
||
147 | throw new Exception('Invalid JSON was returned by the gateway'); |
||
148 | } |
||
149 | |||
150 | return $response; |
||
151 | } |
||
153 |
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