| Conditions | 6 |
| Paths | 8 |
| Total Lines | 73 |
| Code Lines | 49 |
| 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 |
||
| 122 | public function execute() |
||
| 123 | { |
||
| 124 | if (!$this->getRequest()->isPost()) { |
||
| 125 | $resultPage = $this->resultJsonFactory->create(); |
||
| 126 | $resultPage->setHttpResponseCode(404); |
||
| 127 | |||
| 128 | return $resultPage; |
||
| 129 | } |
||
| 130 | |||
| 131 | $resultPage = $this->resultJsonFactory->create(); |
||
| 132 | $response = $this->getRequest()->getContent(); |
||
| 133 | $originalNotification = $this->json->unserialize($response); |
||
| 134 | $authorization = $this->getRequest()->getHeader('Authorization'); |
||
| 135 | $storeId = $this->storeManager->getStore()->getId(); |
||
| 136 | $storeCaptureToken = $this->config->getMerchantGatewayCaptureToken($storeId); |
||
| 137 | if ($storeCaptureToken === $authorization) { |
||
| 138 | $data = $originalNotification['resource']['order']; |
||
| 139 | $order = $this->orderFactory->create()->load($data['id'], 'ext_order_id'); |
||
| 140 | |||
| 141 | if(!$order->getId()) { |
||
| 142 | $resultPage->setHttpResponseCode(406); |
||
| 143 | return $resultPage->setJsonData( |
||
| 144 | $this->json->serialize([ |
||
| 145 | 'error' => 400, |
||
| 146 | 'message' => __('Can not find this order'), |
||
| 147 | ]) |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->logger->debug([ |
||
| 152 | 'webhook' => 'accept', |
||
| 153 | 'ext_order_id' => $data['id'], |
||
| 154 | 'increment_order_id' => $order->getIncrementId(), |
||
| 155 | 'webhook_data' => $response, |
||
| 156 | ]); |
||
| 157 | $payment = $order->getPayment(); |
||
| 158 | if (!$order->getInvoiceCollection()->count()) { |
||
| 159 | try { |
||
| 160 | $isOnline = true; |
||
| 161 | $payment->accept($isOnline); |
||
| 162 | $payment->save(); |
||
| 163 | $order->save(); |
||
| 164 | } catch (\Exception $exc) { |
||
| 165 | $resultPage->setHttpResponseCode(500); |
||
| 166 | return $resultPage->setJsonData( |
||
| 167 | $this->json->serialize([ |
||
| 168 | 'error' => 400, |
||
| 169 | 'message' => $exc->getMessage(), |
||
| 170 | ]) |
||
| 171 | ); |
||
| 172 | } |
||
| 173 | |||
| 174 | return $resultPage->setJsonData( |
||
| 175 | $this->json->serialize([ |
||
| 176 | 'success' => 1, |
||
| 177 | 'status' => $order->getStatus(), |
||
| 178 | 'state' => $order->getState(), |
||
| 179 | ]) |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | |||
| 183 | $resultPage->setHttpResponseCode(400); |
||
| 184 | |||
| 185 | return $resultPage->setJsonData( |
||
| 186 | $this->json->serialize([ |
||
| 187 | 'error' => 400, |
||
| 188 | 'message' => 'The transaction could not be refund', |
||
| 189 | ]) |
||
| 190 | ); |
||
| 191 | } |
||
| 192 | $resultPage->setHttpResponseCode(401); |
||
| 193 | |||
| 194 | return $resultPage; |
||
| 195 | } |
||
| 197 |
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