| Conditions | 12 |
| Paths | 334 |
| Total Lines | 81 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 36 | public function execute() |
||
| 37 | { |
||
| 38 | if (!$this->_formKeyValidator->validate($this->getRequest())) { |
||
| 39 | $this->messageManager->addErrorMessage( |
||
| 40 | __('Your session has expired') |
||
| 41 | ); |
||
| 42 | return $this->resultRedirectFactory->create()->setPath('*/*/'); |
||
| 43 | } |
||
| 44 | |||
| 45 | $params = $this->getRequest()->getParams(); |
||
| 46 | |||
| 47 | try { |
||
| 48 | if (isset($params['qty'])) { |
||
| 49 | $filter = new LocalizedToNormalized( |
||
| 50 | ['locale' => $this->_objectManager->get( |
||
| 51 | \Magento\Framework\Locale\ResolverInterface::class |
||
| 52 | )->getLocale()] |
||
| 53 | ); |
||
| 54 | $params['qty'] = $filter->filter($params['qty']); |
||
| 55 | } |
||
| 56 | |||
| 57 | $product = $this->_initProduct(); |
||
| 58 | $related = $this->getRequest()->getParam('related_product'); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Check product availability |
||
| 62 | */ |
||
| 63 | if (!$product) { |
||
| 64 | return $this->goBack(); |
||
| 65 | } |
||
| 66 | |||
| 67 | $buyNowHelper = $this->_objectManager->create(BuyNowViewModel::class); |
||
| 68 | $cartProducts = $buyNowHelper->keepCartProducts(); |
||
| 69 | if (!$cartProducts) { |
||
| 70 | $this->cart->truncate(); //remove all products from cart |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->cart->addProduct($product, $params); |
||
| 74 | if (!empty($related)) { |
||
| 75 | $this->cart->addProductsByIds(explode(',', $related)); |
||
| 76 | } |
||
| 77 | $this->cart->save(); |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @todo remove wishlist observer \Magento\Wishlist\Observer\AddToCart |
||
| 81 | */ |
||
| 82 | $this->_eventManager->dispatch( |
||
| 83 | 'checkout_cart_add_product_complete', |
||
| 84 | ['product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()] |
||
| 85 | ); |
||
| 86 | |||
| 87 | if (!$this->_checkoutSession->getNoCartRedirect(true)) { |
||
| 88 | $baseUrl = $this->_url->getBaseUrl(); |
||
| 89 | return $this->goBack($baseUrl . 'checkout/', $product); |
||
| 90 | } |
||
| 91 | } catch (\Magento\Framework\Exception\LocalizedException $e) { |
||
| 92 | if ($this->_checkoutSession->getUseNotice(true)) { |
||
| 93 | $this->messageManager->addNoticeMessage( |
||
| 94 | $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($e->getMessage()) |
||
| 95 | ); |
||
| 96 | } else { |
||
| 97 | $messages = array_unique(explode("\n", $e->getMessage())); |
||
| 98 | foreach ($messages as $message) { |
||
| 99 | $this->messageManager->addErrorMessage( |
||
| 100 | $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($message) |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | $url = $this->_checkoutSession->getRedirectUrl(true); |
||
| 105 | if (!$url) { |
||
| 106 | $cartUrl = $this->_objectManager->get(\Magento\Checkout\Helper\Cart::class)->getCartUrl(); |
||
| 107 | $url = $this->_redirect->getRedirectUrl($cartUrl); |
||
| 108 | } |
||
| 109 | return $this->goBack($url); |
||
| 110 | } catch (\Exception $e) { |
||
| 111 | $this->messageManager->addExceptionMessage( |
||
| 112 | $e, |
||
| 113 | __('We can\'t add this item to your shopping cart right now.') |
||
| 114 | ); |
||
| 115 | $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); |
||
| 116 | return $this->goBack(); |
||
| 117 | } |
||
| 120 |
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