| Conditions | 14 |
| Paths | 20 |
| Total Lines | 91 |
| Code Lines | 62 |
| 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 |
||
| 140 | public function execute() |
||
| 141 | { |
||
| 142 | if (!$this->getRequest()->isPost()) { |
||
| 143 | $resultPage = $this->resultJsonFactory->create(); |
||
| 144 | $resultPage->setHttpResponseCode(404); |
||
| 145 | |||
| 146 | return $resultPage; |
||
| 147 | } |
||
| 148 | |||
| 149 | $resultPage = $this->resultJsonFactory->create(); |
||
| 150 | $response = $this->getRequest()->getContent(); |
||
| 151 | $originalNotification = $this->json->unserialize($response); |
||
| 152 | $authorization = $this->getRequest()->getHeader('Authorization'); |
||
| 153 | $storeId = $this->storeManager->getStore()->getId(); |
||
| 154 | $storeCaptureToken = $this->config->getMerchantGatewayRefundToken($storeId); |
||
| 155 | |||
| 156 | if ($storeCaptureToken === $authorization) { |
||
| 157 | $resource = $originalNotification['resource']; |
||
| 158 | $extRefundId = $resource['refund']['id']; |
||
| 159 | $extStatus = $resource['refund']['status']; |
||
| 160 | |||
| 161 | $creditmemos = $this->getCreditMemoByTransactionId($extRefundId); |
||
| 162 | if (count($creditmemos)) { |
||
| 163 | foreach ($creditmemos as $creditmemo) { |
||
| 164 | if ($extStatus === 'REQUESTED') { |
||
| 165 | $creditmemo->setState(Creditmemo::STATE_OPEN); |
||
| 166 | } elseif ($extStatus === 'COMPLETED') { |
||
| 167 | $creditmemo->setState(Creditmemo::STATE_REFUNDED); |
||
| 168 | } elseif ($extStatus === 'FAILED') { |
||
| 169 | $creditmemo->setState(Creditmemo::STATE_CANCELED); |
||
| 170 | } |
||
| 171 | |||
| 172 | try { |
||
| 173 | $creditmemo->save(); |
||
| 174 | } catch (\Exception $exc) { |
||
| 175 | $resultPage->setHttpResponseCode(500); |
||
| 176 | $resultPage->setJsonData( |
||
| 177 | $this->json->serialize([ |
||
| 178 | 'error' => 400, |
||
| 179 | 'message' => $exc->getMessage(), |
||
| 180 | ]) |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | |||
| 184 | continue; |
||
| 185 | } |
||
| 186 | } else { |
||
| 187 | $extOrderId = $resource['refund']['_links']['order']['title']; |
||
| 188 | $creditmemo = $this->createNewCreditMemo($extOrderId, $extRefundId); |
||
| 189 | if ($creditmemo) { |
||
| 190 | if ($extStatus === 'REQUESTED') { |
||
| 191 | $creditmemo->setState(Creditmemo::STATE_OPEN); |
||
| 192 | } elseif ($extStatus === 'COMPLETED') { |
||
| 193 | $creditmemo->setState(Creditmemo::STATE_REFUNDED); |
||
| 194 | } elseif ($extStatus === 'FAILED') { |
||
| 195 | $creditmemo->setState(Creditmemo::STATE_CANCELED); |
||
| 196 | } |
||
| 197 | |||
| 198 | try { |
||
| 199 | $this->creditmemoService->refund($creditmemo); |
||
| 200 | } catch (\Exception $exc) { |
||
| 201 | $resultPage->setHttpResponseCode(500); |
||
| 202 | $resultPage->setJsonData( |
||
| 203 | $this->json->serialize([ |
||
| 204 | 'error' => 400, |
||
| 205 | 'message' => $exc->getMessage(), |
||
| 206 | ]) |
||
| 207 | ); |
||
| 208 | } |
||
| 209 | } else { |
||
| 210 | return $resultPage->setJsonData( |
||
| 211 | $this->json->serialize([ |
||
| 212 | 'error' => 404, |
||
| 213 | 'message' => 'The transaction could not be refund', |
||
| 214 | ]) |
||
| 215 | ); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | return $resultPage->setJsonData( |
||
| 220 | $this->json->serialize([ |
||
| 221 | 'success' => 1, |
||
| 222 | 'extOrderId' => $extRefundId, |
||
| 223 | 'state' => $creditmemo->getState(), |
||
| 224 | ]) |
||
| 225 | ); |
||
| 226 | } |
||
| 227 | |||
| 228 | $resultPage->setHttpResponseCode(401); |
||
| 229 | |||
| 230 | return $resultPage; |
||
| 231 | } |
||
| 285 |
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