| Conditions | 16 |
| Paths | 1588 |
| Total Lines | 93 |
| Code Lines | 67 |
| 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 |
||
| 88 | public function execute() |
||
| 89 | { |
||
| 90 | $mainQuoteId = $this->cart->getQuote()->getEntityId(); |
||
| 91 | if (!$this->_formKeyValidator->validate($this->getRequest())) { |
||
| 92 | return $this->resultRedirectFactory->create()->setPath('*/*/'); |
||
| 93 | } |
||
| 94 | $params = $this->getRequest()->getParams(); |
||
| 95 | try { |
||
| 96 | if (isset($params['qty'])) { |
||
| 97 | $filter = new \Zend_Filter_LocalizedToNormalized( |
||
| 98 | ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()] |
||
| 99 | ); |
||
| 100 | $params['qty'] = $filter->filter($params['qty']); |
||
| 101 | } |
||
| 102 | $product = $this->_initProduct(); |
||
| 103 | $related = $this->getRequest()->getParam('related_product'); |
||
| 104 | if (!$product) { |
||
| 105 | return $this->goBack(); |
||
| 106 | } |
||
| 107 | $cartProducts = $this->scopeConfig->getValue( |
||
| 108 | 'buynow/general/keep_cart_products', |
||
| 109 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE |
||
| 110 | ); |
||
| 111 | if (!$cartProducts) { |
||
| 112 | $cartRestore = $this->scopeConfig->getValue( |
||
| 113 | 'buynow/general/restore_cart_products', |
||
| 114 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE |
||
| 115 | ); |
||
| 116 | if ($cartRestore) { |
||
| 117 | if ($mainQuoteId) { |
||
| 118 | $quoteRepo = $this->quoteRepository->get($mainQuoteId); |
||
| 119 | $quoteRepo->setData('is_active', 0); |
||
| 120 | $this->quoteRepository->save($quoteRepo); |
||
| 121 | } |
||
| 122 | $store = $this->storeManager->getStore(); |
||
| 123 | $websiteId = $this->storeManager->getStore()->getWebsiteId(); |
||
| 124 | $quoteData = $this->quoteFactory->create(); |
||
| 125 | $quoteData->setStore($store); |
||
| 126 | $quoteData->setCurrency(); |
||
| 127 | if ($this->cart->getQuote()->getCustomerId()) { |
||
| 128 | $customerId = $this->cart->getQuote()->getCustomerId(); |
||
| 129 | $customerEmail = $this->cart->getQuote()->getCustomerEmail(); |
||
| 130 | $customerRepoData = $this->customerRepository->getById($customerId); |
||
| 131 | $quoteData->assignCustomer($customerRepoData); |
||
| 132 | } |
||
| 133 | if ($mainQuoteId) { |
||
| 134 | $quoteData->setBuyNowId($mainQuoteId); |
||
| 135 | } |
||
| 136 | $quoteData->save(); |
||
| 137 | $this->cart->setQuote($quoteData); |
||
| 138 | } else { |
||
| 139 | $this->cart->truncate(); //remove all products from cart |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $this->cart->addProduct($product, $params); |
||
| 143 | if (!empty($related)) { |
||
| 144 | $this->cart->addProductsByIds(explode(',', $related)); |
||
| 145 | } |
||
| 146 | $this->cart->save(); |
||
| 147 | |||
| 148 | // $this->_eventManager->dispatch( |
||
| 149 | // 'checkout_cart_add_product_complete', |
||
| 150 | // ['product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()] |
||
| 151 | // ); |
||
| 152 | |||
| 153 | if (!$this->_checkoutSession->getNoCartRedirect(true)) { |
||
| 154 | $baseUrl = $this->_objectManager->get('\Magento\Store\Model\StoreManagerInterface') |
||
| 155 | ->getStore()->getBaseUrl(); |
||
| 156 | return $this->goBack($baseUrl . 'checkout/', $product); |
||
| 157 | } |
||
| 158 | } catch (\Magento\Framework\Exception\LocalizedException $e) { |
||
| 159 | if ($this->_checkoutSession->getUseNotice(true)) { |
||
| 160 | $this->messageManager->addNotice( |
||
| 161 | $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($e->getMessage()) |
||
| 162 | ); |
||
| 163 | } else { |
||
| 164 | $messages = array_unique(explode("\n", $e->getMessage())); |
||
| 165 | foreach ($messages as $message) { |
||
| 166 | $this->messageManager->addError( |
||
| 167 | $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($message) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | $url = $this->_checkoutSession->getRedirectUrl(true); |
||
| 172 | if (!$url) { |
||
| 173 | $cartUrl = $this->_objectManager->get('Magento\Checkout\Helper\Cart')->getCartUrl(); |
||
| 174 | $url = $this->_redirect->getRedirectUrl($cartUrl); |
||
| 175 | } |
||
| 176 | return $this->goBack($url); |
||
| 177 | } catch (\Exception $e) { |
||
| 178 | $this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.')); |
||
| 179 | $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); |
||
| 180 | return $this->goBack(); |
||
| 181 | } |
||
| 184 |
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