Skip to content

Commit

Permalink
PHPStan: use service contracts to persist entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin-Magmodules committed Sep 26, 2024
1 parent 56aa035 commit 78e0200
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions Controller/Wishlist/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Framework\App\ActionInterface;
use Magento\Wishlist\Controller\WishlistProviderInterface;
use Magento\Wishlist\Model\AuthenticationStateInterface;
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
use Magmodules\Sooqr\Api\Config\RepositoryInterface as ConfigProvider;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Controller\Result\Redirect;
Expand Down Expand Up @@ -86,24 +87,11 @@ class Add implements ActionInterface
* @var ResultFactory
*/
private $resultFactory;

/**
* Add constructor.
*
* @param ConfigProvider $configProvider
* @param Session $customerSession
* @param WishlistProviderInterface $wishlistProvider
* @param ProductRepositoryInterface $productRepository
* @param WishlistHelper $wishlistHelper
* @param RedirectInterface $redirect
* @param LogRepository $logRepository
* @param AuthenticationStateInterface $authenticationState
* @param ScopeConfigInterface $config
* @param MessageManagerInterface $messageManager
* @param RequestInterface $request
* @param EventManagerInterface $eventManager
* @param ResultFactory $resultFactory
* @var WishlistResourceModel
*/
private $wishlistResource;

public function __construct(
ConfigProvider $configProvider,
Session $customerSession,
Expand All @@ -117,6 +105,7 @@ public function __construct(
MessageManagerInterface $messageManager,
RequestInterface $request,
EventManagerInterface $eventManager,
WishlistResourceModel $wishlistResource,
ResultFactory $resultFactory
) {
$this->configProvider = $configProvider;
Expand All @@ -132,6 +121,7 @@ public function __construct(
$this->request = $request;
$this->eventManager = $eventManager;
$this->resultFactory = $resultFactory;
$this->wishlistResource = $wishlistResource;
}

/**
Expand All @@ -140,7 +130,7 @@ public function __construct(
* We can't extend default execute method, because it works only with POST requests
*
* @return Redirect
* @throws NotFoundException
* @throws NotFoundException|SessionException
*/
public function execute(): Redirect
{
Expand Down Expand Up @@ -193,7 +183,7 @@ public function execute(): Redirect
throw new LocalizedException(__($result));
}
if ($wishlist->isObjectNew()) {
$wishlist->save();
$this->wishlistResource->save($wishlist);
}
$this->eventManager->dispatch(
'wishlist_add_product',
Expand Down

0 comments on commit 78e0200

Please sign in to comment.