66namespace Magento \Wishlist \Controller \Index ;
77
88use Magento \Catalog \Api \ProductRepositoryInterface ;
9- use Magento \Framework \App \Action ;
9+ use Magento \Customer \Model \Session ;
10+ use Magento \Framework \App \Action \Context ;
1011use Magento \Framework \App \Action \HttpPostActionInterface ;
12+ use Magento \Framework \Controller \Result \Redirect ;
1113use Magento \Framework \Data \Form \FormKey \Validator ;
14+ use Magento \Framework \Exception \LocalizedException ;
1215use Magento \Framework \Exception \NotFoundException ;
1316use Magento \Framework \Exception \NoSuchEntityException ;
1417use Magento \Framework \Controller \ResultFactory ;
1518use Magento \Framework \App \ObjectManager ;
1619use Magento \Framework \UrlInterface ;
1720use Magento \Framework \App \Response \RedirectInterface ;
21+ use Magento \Framework \Controller \ResultInterface ;
22+ use Magento \Wishlist \Controller \WishlistProviderInterface ;
1823
1924/**
2025 * Wish list Add controller
2429class Add extends \Magento \Wishlist \Controller \AbstractIndex implements HttpPostActionInterface
2530{
2631 /**
27- * @var \Magento\Wishlist\Controller\ WishlistProviderInterface
32+ * @var WishlistProviderInterface
2833 */
2934 protected $ wishlistProvider ;
3035
3136 /**
32- * @var \Magento\Customer\Model\ Session
37+ * @var Session
3338 */
3439 protected $ _customerSession ;
3540
@@ -43,23 +48,29 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
4348 */
4449 protected $ formKeyValidator ;
4550
51+ /**
52+ * @var RedirectInterface
53+ */
4654 private $ redirect ;
4755
56+ /**
57+ * @var mixed UrlInterface
58+ */
4859 private $ urlBuilder ;
4960
5061 /**
51- * @param Action\ Context $context
52- * @param \Magento\Customer\Model\ Session $customerSession
53- * @param \Magento\Wishlist\Controller\ WishlistProviderInterface $wishlistProvider
62+ * @param Context $context
63+ * @param Session $customerSession
64+ * @param WishlistProviderInterface $wishlistProvider
5465 * @param ProductRepositoryInterface $productRepository
5566 * @param Validator $formKeyValidator
56- * @param RedirectInterface $redirect
57- * @param UrlInterface $urlBuilder
67+ * @param RedirectInterface|null $redirect
68+ * @param UrlInterface|null $urlBuilder
5869 */
5970 public function __construct (
60- Action \ Context $ context ,
61- \ Magento \ Customer \ Model \ Session $ customerSession ,
62- \ Magento \ Wishlist \ Controller \ WishlistProviderInterface $ wishlistProvider ,
71+ Context $ context ,
72+ Session $ customerSession ,
73+ WishlistProviderInterface $ wishlistProvider ,
6374 ProductRepositoryInterface $ productRepository ,
6475 Validator $ formKeyValidator ,
6576 RedirectInterface $ redirect = null ,
@@ -75,15 +86,17 @@ public function __construct(
7586 }
7687
7788 /**
78- * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
89+ * Adding new item
90+ *
91+ * @return ResultInterface
7992 * @throws NotFoundException
8093 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
8194 * @SuppressWarnings(PHPMD.NPathComplexity)
8295 * @SuppressWarnings(PHPMD.UnusedLocalVariable)
8396 */
8497 public function execute ()
8598 {
86- /** @var \Magento\Framework\Controller\Result\ Redirect $resultRedirect */
99+ /** @var Redirect $resultRedirect */
87100 $ resultRedirect = $ this ->resultFactory ->create (ResultFactory::TYPE_REDIRECT );
88101 if (!$ this ->formKeyValidator ->validate ($ this ->getRequest ())) {
89102 return $ resultRedirect ->setPath ('*/ ' );
@@ -126,7 +139,7 @@ public function execute()
126139
127140 $ result = $ wishlist ->addNewItem ($ product , $ buyRequest );
128141 if (is_string ($ result )) {
129- throw new \ Magento \ Framework \ Exception \ LocalizedException (__ ($ result ));
142+ throw new LocalizedException (__ ($ result ));
130143 }
131144 if ($ wishlist ->isObjectNew ()) {
132145 $ wishlist ->save ();
@@ -153,7 +166,7 @@ public function execute()
153166 ]
154167 );
155168 // phpcs:disable Magento2.Exceptions.ThrowCatch
156- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
169+ } catch (LocalizedException $ e ) {
157170 $ this ->messageManager ->addErrorMessage (
158171 __ ('We can \'t add the item to Wish List right now: %1. ' , $ e ->getMessage ())
159172 );
0 commit comments