| Conditions | 9 |
| Paths | 54 |
| Total Lines | 99 |
| Code Lines | 66 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 154 | public function execute() |
||
| 155 | { |
||
| 156 | if (!$this->getRequest()->isPost()) { |
||
| 157 | $resultPage = $this->resultJsonFactory->create(); |
||
| 158 | $resultPage->setHttpResponseCode(404); |
||
| 159 | |||
| 160 | return $resultPage; |
||
| 161 | } |
||
| 162 | |||
| 163 | $resultPage = $this->resultJsonFactory->create(); |
||
| 164 | $response = $this->getRequest()->getContent(); |
||
| 165 | $originalNotification = $this->json->unserialize($response); |
||
| 166 | $authorization = $this->getRequest()->getHeader('Authorization'); |
||
| 167 | $storeId = $this->storeManager->getStore()->getId(); |
||
| 168 | $storeCaptureToken = $this->config->getMerchantGatewayCancelToken($storeId); |
||
| 169 | if ($storeCaptureToken === $authorization) { |
||
| 170 | $data = $originalNotification['resource']['order']; |
||
| 171 | $order = $this->orderFactory->create()->load($data['id'], 'ext_order_id'); |
||
| 172 | |||
| 173 | if(!$order->getId()) { |
||
| 174 | $resultPage->setHttpResponseCode(406); |
||
| 175 | return $resultPage->setJsonData( |
||
| 176 | $this->json->serialize([ |
||
| 177 | 'error' => 400, |
||
| 178 | 'message' => __('Can not find this order'), |
||
| 179 | ]) |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | |||
| 183 | $this->logger->debug([ |
||
| 184 | 'webhook' => 'deny', |
||
| 185 | 'ext_order_id' => $data['id'], |
||
| 186 | 'increment_order_id' => $order->getIncrementId(), |
||
| 187 | 'webhook_data' => $response, |
||
| 188 | ]); |
||
| 189 | $payment = $order->getPayment(); |
||
| 190 | if ($order->canVoidPayment()) { |
||
| 191 | try { |
||
| 192 | $isOnline = true; |
||
| 193 | $payment->void($isOnline); |
||
| 194 | $payment->save(); |
||
| 195 | $cancelDetailsAdmin = __('We did not record the payment.'); |
||
| 196 | $cancelDetailsCus = __('The payment deadline has been exceeded.'); |
||
| 197 | if (isset($data['payments'])) { |
||
| 198 | foreach ($data['payments'] as $payment) { |
||
| 199 | if (isset($payment['cancellationDetails'])) { |
||
| 200 | $cancelCode = $payment['cancellationDetails']['code']; |
||
| 201 | $cancelDescription = $payment['cancellationDetails']['description']; |
||
| 202 | $cancelBy = $payment['cancellationDetails']['cancelledBy']; |
||
| 203 | $cancelDetailsAdmin = __('%1, code %2, by %3', $cancelDescription, $cancelCode, $cancelBy); |
||
| 204 | $cancelDetailsCus = __('%1', $cancelDescription); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
||
| 208 | /** customer information for cancel **/ |
||
| 209 | $history = $order->addStatusHistoryComment($cancelDetailsCus); |
||
| 210 | $history->setIsVisibleOnFront(1); |
||
| 211 | $history->setIsCustomerNotified(1); |
||
| 212 | // $order->sendOrderUpdateEmail(1, $cancelDetailsCus); |
||
| 213 | |||
| 214 | /** admin information for cancel **/ |
||
| 215 | $history = $order->addStatusHistoryComment($cancelDetailsAdmin); |
||
| 216 | $history->setIsVisibleOnFront(0); |
||
| 217 | $history->setIsCustomerNotified(0); |
||
| 218 | $order->save(); |
||
| 219 | |||
| 220 | $this->orderCommentSender->send($order, 1, $cancelDetailsCus); |
||
| 221 | } catch (\Exception $exc) { |
||
| 222 | $resultPage->setHttpResponseCode(500); |
||
| 223 | return $resultPage->setJsonData( |
||
| 224 | $this->json->serialize([ |
||
| 225 | 'error' => 400, |
||
| 226 | 'message' => $exc->getMessage(), |
||
| 227 | ]) |
||
| 228 | ); |
||
| 229 | } |
||
| 230 | |||
| 231 | return $resultPage->setJsonData( |
||
| 232 | $this->json->serialize([ |
||
| 233 | 'success' => 1, |
||
| 234 | 'status' => $order->getStatus(), |
||
| 235 | 'state' => $order->getState(), |
||
| 236 | ]) |
||
| 237 | ); |
||
| 238 | } |
||
| 239 | |||
| 240 | $resultPage->setHttpResponseCode(201); |
||
| 241 | |||
| 242 | return $resultPage->setJsonData( |
||
| 243 | $this->json->serialize([ |
||
| 244 | 'error' => 400, |
||
| 245 | 'message' => 'The transaction could not be refund', |
||
| 246 | ]) |
||
| 247 | ); |
||
| 248 | } |
||
| 249 | |||
| 250 | $resultPage->setHttpResponseCode(401); |
||
| 251 | |||
| 252 | return $resultPage; |
||
| 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