diff --git a/Block/Cart/ApplePay.php b/Block/Cart/ApplePay.php index 203db28..0e7a82d 100644 --- a/Block/Cart/ApplePay.php +++ b/Block/Cart/ApplePay.php @@ -4,7 +4,6 @@ namespace Swarming\SubscribePro\Block\Cart; use Magento\Checkout\Model\Session; -use Magento\Directory\Helper\Data as DirectoryHelper; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; @@ -21,10 +20,6 @@ class ApplePay extends Template * @var Quote */ private $quote; - /** - * @var DirectoryHelper - */ - private $directoryHelper; /** * @var PaymentRequestConfig */ @@ -58,7 +53,6 @@ class ApplePay extends Template * * @param Context $context * @param Quote $quote - * @param DirectoryHelper $directoryHelper * @param PaymentRequestConfig $paymentRequestConfig * @param ApplePayConfigProvider $applePayConfigProvider * @param JsonSerializer $jsonJsonSerializer @@ -70,7 +64,6 @@ class ApplePay extends Template public function __construct( Context $context, Quote $quote, - DirectoryHelper $directoryHelper, PaymentRequestConfig $paymentRequestConfig, ApplePayConfigProvider $applePayConfigProvider, JsonSerializer $jsonJsonSerializer, @@ -81,7 +74,6 @@ public function __construct( ) { parent::__construct($context, $data); $this->quote = $quote; - $this->directoryHelper = $directoryHelper; $this->paymentRequestConfig = $paymentRequestConfig; $this->applePayConfigProvider = $applePayConfigProvider; $this->jsonJsonSerializer = $jsonJsonSerializer; diff --git a/Block/Customer/SubscriptionsDirectoryDataProcessor.php b/Block/Customer/SubscriptionsDirectoryDataProcessor.php index 8e61645..3b81fbd 100644 --- a/Block/Customer/SubscriptionsDirectoryDataProcessor.php +++ b/Block/Customer/SubscriptionsDirectoryDataProcessor.php @@ -93,7 +93,7 @@ public function process($jsLayout) */ protected function getCountryOptions() { - if (!isset($this->countryOptions)) { + if (!$this->countryOptions) { $this->countryOptions = $this->countryCollectionFactory->create()->loadByStore( $this->storeManager->getStore()->getId() )->toOptionArray(); @@ -107,10 +107,11 @@ protected function getCountryOptions() * Get region options list. * * @return array + * @throws NoSuchEntityException */ protected function getRegionOptions() { - if (!isset($this->regionOptions)) { + if (!$this->regionOptions) { $this->regionOptions = $this->regionCollectionFactory->create()->addAllowedCountriesFilter( $this->storeManager->getStore()->getId() )->toOptionArray(); diff --git a/Block/Vault/Edit.php b/Block/Vault/Edit.php index e81b878..f74330a 100644 --- a/Block/Vault/Edit.php +++ b/Block/Vault/Edit.php @@ -132,7 +132,7 @@ protected function loadToken($publicHash) protected function loadProfile() { $profile = $this->platformPaymentProfileService->loadProfile($this->token->getGatewayToken()); - if (!$profile) { + if (!$profile->getId()) { throw new LocalizedException(__('The saved credit is not found.')); } $this->profile = $profile; @@ -148,7 +148,7 @@ protected function initPageTitle() { /** @var \Magento\Theme\Block\Html\Title $pageMainTitle */ $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); - if ($pageMainTitle) { + if ($pageMainTitle !== null) { $message = $this->token ? __('Edit Card: ending %1', $this->getNumberLast4Digits()) : __('Add New Card'); $pageMainTitle->setPageTitle($message); } diff --git a/Gateway/Command/ApplePay/AuthorizeCommand.php b/Gateway/Command/ApplePay/AuthorizeCommand.php index 97a22ea..cea5d09 100644 --- a/Gateway/Command/ApplePay/AuthorizeCommand.php +++ b/Gateway/Command/ApplePay/AuthorizeCommand.php @@ -23,9 +23,7 @@ protected function processTransaction(array $requestData) } $transaction = $this->platformTransactionService->createTransaction($requestData); - if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE]) - && $requestData[VaultConfigProvider::IS_ACTIVE_CODE] - ) { + if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE])) { $profileId = $requestData[PaymentDataBuilder::PLATFORM_PROFILE_ID]; $this->platformTransactionService->authorizeByProfile([ VaultDataBuilder::PAYMENT_PROFILE_ID => $profileId diff --git a/Gateway/Command/ApplePay/PurchaseCommand.php b/Gateway/Command/ApplePay/PurchaseCommand.php index 3d54add..45f897d 100644 --- a/Gateway/Command/ApplePay/PurchaseCommand.php +++ b/Gateway/Command/ApplePay/PurchaseCommand.php @@ -26,9 +26,7 @@ protected function processTransaction(array $requestData) throw new \InvalidArgumentException(__('Payment token is not passed')); } $transaction = $this->platformTransactionService->createTransaction($requestData); - if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE]) - && $requestData[VaultConfigProvider::IS_ACTIVE_CODE] - ) { + if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE])) { $this->platformTransactionService->purchaseByProfile([ VaultDataBuilder::PAYMENT_PROFILE_ID => $requestData[ApplePayPaymentDataBuilder::PLATFORM_PROFILE_ID] ], $transaction); diff --git a/Gateway/Command/AuthorizeCommand.php b/Gateway/Command/AuthorizeCommand.php index 86d1fd8..afa47b2 100644 --- a/Gateway/Command/AuthorizeCommand.php +++ b/Gateway/Command/AuthorizeCommand.php @@ -23,8 +23,7 @@ protected function processTransaction(array $requestData) } $transaction = $this->platformTransactionService->createTransaction($requestData); - if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE]) - && $requestData[VaultConfigProvider::IS_ACTIVE_CODE]) { + if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE])) { $profile = $this->createProfile($requestData); $this->platformTransactionService->authorizeByProfile([ VaultDataBuilder::PAYMENT_PROFILE_ID => $profile->getId() diff --git a/Gateway/Command/PurchaseCommand.php b/Gateway/Command/PurchaseCommand.php index 85efb36..6beb586 100644 --- a/Gateway/Command/PurchaseCommand.php +++ b/Gateway/Command/PurchaseCommand.php @@ -24,8 +24,7 @@ protected function processTransaction(array $requestData) } $transaction = $this->platformTransactionService->createTransaction($requestData); - if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE]) - && $requestData[VaultConfigProvider::IS_ACTIVE_CODE]) { + if (!empty($requestData[VaultConfigProvider::IS_ACTIVE_CODE])) { $profile = $this->createProfile($requestData); $this->platformTransactionService->purchaseByProfile([ VaultDataBuilder::PAYMENT_PROFILE_ID => $profile->getId() diff --git a/Model/ApplePay/OrderService.php b/Model/ApplePay/OrderService.php index 37ee60a..5a8a565 100644 --- a/Model/ApplePay/OrderService.php +++ b/Model/ApplePay/OrderService.php @@ -4,17 +4,11 @@ namespace Swarming\SubscribePro\Model\ApplePay; use Magento\Checkout\Helper\Data as CheckoutHelperData; -use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Framework\Exception\LocalizedException; -use Magento\Payment\Model\Method\Logger as PaymentLogger; use Magento\Quote\Api\CartRepositoryInterface; -use Magento\Quote\Model\BillingAddressManagement; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Address as QuoteAddress; -use Magento\Quote\Model\Quote\AddressFactory; use Magento\Quote\Model\QuoteManagement; -use Magento\Quote\Model\ShippingAddressManagement; -use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Psr\Log\LoggerInterface; class OrderService @@ -27,34 +21,10 @@ class OrderService * @var QuoteManagement */ private $quoteManagement; - /** - * @var AddressFactory - */ - private $addressFactory; - /** - * @var ShippingAddressManagement - */ - private $shippingAddressManagement; - /** - * @var BillingAddressManagement - */ - private $billingAddressManagement; - /** - * @var PaymentLogger - */ - private $paymentLogger; - /** - * @var CheckoutSession - */ - private $checkoutSession; /** * @var CheckoutHelperData */ private $checkoutHelperData; - /** - * @var OrderSender - */ - private $orderSender; /** * @var LoggerInterface */ @@ -63,38 +33,20 @@ class OrderService /** * OrderService constructor. * - * @param CartRepositoryInterface $quoteRepository - * @param QuoteManagement $quoteManagement - * @param CheckoutSession $checkoutSession - * @param AddressFactory $addressFactory - * @param ShippingAddressManagement $shippingAddressManagement - * @param BillingAddressManagement $billingAddressManagement - * @param PaymentLogger $paymentLogger - * @param CheckoutHelperData $checkoutHelperData - * @param OrderSender $orderSender - * @param LoggerInterface $logger + * @param CartRepositoryInterface $quoteRepository + * @param QuoteManagement $quoteManagement + * @param CheckoutHelperData $checkoutHelperData + * @param LoggerInterface $logger */ public function __construct( CartRepositoryInterface $quoteRepository, QuoteManagement $quoteManagement, - CheckoutSession $checkoutSession, - AddressFactory $addressFactory, - ShippingAddressManagement $shippingAddressManagement, - BillingAddressManagement $billingAddressManagement, - PaymentLogger $paymentLogger, CheckoutHelperData $checkoutHelperData, - OrderSender $orderSender, LoggerInterface $logger ) { $this->quoteRepository = $quoteRepository; $this->quoteManagement = $quoteManagement; - $this->addressFactory = $addressFactory; - $this->shippingAddressManagement = $shippingAddressManagement; - $this->billingAddressManagement = $billingAddressManagement; - $this->paymentLogger = $paymentLogger; - $this->checkoutSession = $checkoutSession; $this->checkoutHelperData = $checkoutHelperData; - $this->orderSender = $orderSender; $this->logger = $logger; } diff --git a/Model/ApplePay/PaymentRequestConfig.php b/Model/ApplePay/PaymentRequestConfig.php index 0c28591..2f526c0 100644 --- a/Model/ApplePay/PaymentRequestConfig.php +++ b/Model/ApplePay/PaymentRequestConfig.php @@ -3,7 +3,6 @@ namespace Swarming\SubscribePro\Model\ApplePay; -use Magento\Checkout\Helper\Data as CheckoutHelper; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Directory\Helper\Data as DirectoryHelper; use Magento\Directory\Model\Currency; @@ -31,10 +30,6 @@ class PaymentRequestConfig extends DataObject * @var SessionManagerInterface */ private $checkoutSession; - /** - * @var CheckoutHelper - */ - private $checkoutHelper; /** * @var Currency */ @@ -56,25 +51,22 @@ class PaymentRequestConfig extends DataObject * PaymentRequestConfig constructor. * * @param SessionManagerInterface $checkoutSession - * @param DirectoryHelper $directoryHelper - * @param Currency $currency - * @param CheckoutHelper $checkoutHelper - * @param PlatformOAuth $platformOAuth + * @param DirectoryHelper $directoryHelper + * @param Currency $currency + * @param PlatformOAuth $platformOAuth * @param PlatformManagerCustomer $platformManagerCustomer - * @param LoggerInterface $logger + * @param LoggerInterface $logger */ public function __construct( SessionManagerInterface $checkoutSession, DirectoryHelper $directoryHelper, Currency $currency, - CheckoutHelper $checkoutHelper, PlatformOAuth $platformOAuth, PlatformManagerCustomer $platformManagerCustomer, LoggerInterface $logger ) { $this->checkoutSession = $checkoutSession; $this->directoryHelper = $directoryHelper; - $this->checkoutHelper = $checkoutHelper; $this->currency = $currency; $this->platformOAuth = $platformOAuth; $this->platformManagerCustomer = $platformManagerCustomer; diff --git a/Model/ApplePay/PaymentService.php b/Model/ApplePay/PaymentService.php index a383223..ce5c1dd 100644 --- a/Model/ApplePay/PaymentService.php +++ b/Model/ApplePay/PaymentService.php @@ -13,7 +13,6 @@ use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; use Magento\Framework\Session\SessionManagerInterface; use Magento\Quote\Api\Data\AddressInterface; -use Magento\Quote\Api\Data\CartInterface; use Magento\Quote\Model\Quote; use Magento\Quote\Model\Quote\Address as QuoteAddress; use Magento\Quote\Model\QuoteManagement; @@ -49,10 +48,6 @@ class PaymentService * @var CustomerSession */ private $customerSession; - /** - * @var Currency - */ - private $currency; /** * @var DirectoryRegion */ @@ -69,10 +64,6 @@ class PaymentService * @var OrderService */ private $orderService; - /** - * @var QuoteManagement - */ - private $quoteManagement; /** * @var QuotePaymentResourceModel */ @@ -85,56 +76,43 @@ class PaymentService * @var JsonSerializer */ private $jsonSerializer; - /** - * @var LoggerInterface - */ - private $logger; /** * Construct the payment service. * - * @param SessionManagerInterface $checkoutSession - * @param CustomerSession $customerSession - * @param Currency $currency - * @param DirectoryRegion $directoryRegion - * @param PlatformCustomer $platformCustomer + * @param SessionManagerInterface $checkoutSession + * @param CustomerSession $customerSession + * @param DirectoryRegion $directoryRegion + * @param PlatformCustomer $platformCustomer * @param PlatformApplePayPaymentProfile $platformPaymentProfile - * @param OrderService $orderService - * @param QuoteManagement $quoteManagement - * @param QuotePaymentResourceModel $quotePaymentResourceModel - * @param QuoteResourceModel $quoteResourceModel - * @param JsonSerializer $jsonSerializer - * @param ApplePayVaultHelper $vault - * @param LoggerInterface $logger + * @param OrderService $orderService + * @param QuotePaymentResourceModel $quotePaymentResourceModel + * @param QuoteResourceModel $quoteResourceModel + * @param JsonSerializer $jsonSerializer + * @param ApplePayVaultHelper $vault */ public function __construct( SessionManagerInterface $checkoutSession, CustomerSession $customerSession, - Currency $currency, DirectoryRegion $directoryRegion, PlatformCustomer $platformCustomer, PlatformApplePayPaymentProfile $platformPaymentProfile, OrderService $orderService, - QuoteManagement $quoteManagement, QuotePaymentResourceModel $quotePaymentResourceModel, QuoteResourceModel $quoteResourceModel, JsonSerializer $jsonSerializer, - ApplePayVaultHelper $vault, - LoggerInterface $logger + ApplePayVaultHelper $vault ) { $this->checkoutSession = $checkoutSession; $this->customerSession = $customerSession; - $this->currency = $currency; $this->directoryRegion = $directoryRegion; $this->platformCustomer = $platformCustomer; $this->platformPaymentProfile = $platformPaymentProfile; $this->orderService = $orderService; - $this->quoteManagement = $quoteManagement; $this->quotePaymentResourceModel = $quotePaymentResourceModel; $this->quoteResourceModel = $quoteResourceModel; $this->jsonSerializer = $jsonSerializer; $this->applePayVaultHelper = $vault; - $this->logger = $logger; } /** diff --git a/Observer/Checkout/SubmitAllAfter.php b/Observer/Checkout/SubmitAllAfter.php index d26f68b..ed58011 100644 --- a/Observer/Checkout/SubmitAllAfter.php +++ b/Observer/Checkout/SubmitAllAfter.php @@ -2,48 +2,48 @@ namespace Swarming\SubscribePro\Observer\Checkout; +use Magento\Checkout\Model\Session; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Model\Order; +use Psr\Log\LoggerInterface; use Swarming\SubscribePro\Gateway\Config\ApplePayConfigProvider; use Swarming\SubscribePro\Gateway\Config\ConfigProvider as GatewayConfigProvider; +use Swarming\SubscribePro\Helper\ThirdPartyPayment; +use Swarming\SubscribePro\Model\Config\General; use Swarming\SubscribePro\Model\Quote\SubscriptionCreator; class SubmitAllAfter implements ObserverInterface { /** - * @var \Swarming\SubscribePro\Model\Config\General + * @var General */ protected $generalConfig; /** - * @var \Magento\Checkout\Model\Session + * @var Session */ protected $checkoutSession; /** - * @var \Swarming\SubscribePro\Model\Quote\SubscriptionCreator + * @var SubscriptionCreator */ protected $subscriptionCreator; /** - * @var \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor + * @var CartItemOptionsProcessor */ protected $cartItemOptionProcessor; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ protected $logger; /** - * @var \Swarming\SubscribePro\Model\Config\ThirdPartyPayment - */ - private $thirdPartyPaymentConfig; - - /** - * @var \Swarming\SubscribePro\Helper\ThirdPartyPayment + * @var ThirdPartyPayment */ private $thirdPartyPayment; @@ -56,29 +56,26 @@ class SubmitAllAfter implements ObserverInterface ]; /** - * @param \Swarming\SubscribePro\Model\Config\General $generalConfig - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Swarming\SubscribePro\Model\Quote\SubscriptionCreator $subscriptionCreator - * @param \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor $cartItemOptionProcessor - * @param \Psr\Log\LoggerInterface $logger - * @param \Swarming\SubscribePro\Model\Config\ThirdPartyPayment $thirdPartyPaymentConfig - * @param \Swarming\SubscribePro\Helper\ThirdPartyPayment $thirdPartyPayment + * @param General $generalConfig + * @param Session $checkoutSession + * @param SubscriptionCreator $subscriptionCreator + * @param CartItemOptionsProcessor $cartItemOptionProcessor + * @param LoggerInterface $logger + * @param ThirdPartyPayment $thirdPartyPayment */ public function __construct( - \Swarming\SubscribePro\Model\Config\General $generalConfig, - \Magento\Checkout\Model\Session $checkoutSession, - \Swarming\SubscribePro\Model\Quote\SubscriptionCreator $subscriptionCreator, - \Magento\Quote\Model\Quote\Item\CartItemOptionsProcessor $cartItemOptionProcessor, - \Psr\Log\LoggerInterface $logger, - \Swarming\SubscribePro\Model\Config\ThirdPartyPayment $thirdPartyPaymentConfig, - \Swarming\SubscribePro\Helper\ThirdPartyPayment $thirdPartyPayment + General $generalConfig, + Session $checkoutSession, + SubscriptionCreator $subscriptionCreator, + CartItemOptionsProcessor $cartItemOptionProcessor, + LoggerInterface $logger, + ThirdPartyPayment $thirdPartyPayment ) { $this->generalConfig = $generalConfig; $this->checkoutSession = $checkoutSession; $this->subscriptionCreator = $subscriptionCreator; $this->cartItemOptionProcessor = $cartItemOptionProcessor; $this->logger = $logger; - $this->thirdPartyPaymentConfig = $thirdPartyPaymentConfig; $this->thirdPartyPayment = $thirdPartyPayment; } diff --git a/Observer/Payment/Availability.php b/Observer/Payment/Availability.php index 026bf15..77ba5a9 100644 --- a/Observer/Payment/Availability.php +++ b/Observer/Payment/Availability.php @@ -2,52 +2,53 @@ namespace Swarming\SubscribePro\Observer\Payment; +use Magento\Checkout\Model\Session; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Payment\Model\Method\Free; +use Psr\Log\LoggerInterface; use Swarming\SubscribePro\Gateway\Config\ApplePayConfigProvider; use Swarming\SubscribePro\Gateway\Config\Config; use Swarming\SubscribePro\Gateway\Config\ConfigProvider; +use Swarming\SubscribePro\Helper\Quote; +use Swarming\SubscribePro\Helper\ThirdPartyPayment; class Availability implements ObserverInterface { /** - * @var \Magento\Checkout\Model\Session + * @var Session */ protected $checkoutSession; /** - * @var \Swarming\SubscribePro\Helper\Quote + * @var Quote */ protected $quoteHelper; /** - * @var \Swarming\SubscribePro\Model\Config\ThirdPartyPayment + * @var ThirdPartyPayment */ - private $thirdPartyPaymentConfig; + private $thirdPartyPayment; /** - * @var \Swarming\SubscribePro\Helper\ThirdPartyPayment + * @var LoggerInterface */ - private $thirdPartyPayment; - private \Psr\Log\LoggerInterface $logger; + private LoggerInterface $logger; /** - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Swarming\SubscribePro\Helper\Quote $quoteHelper - * @param \Swarming\SubscribePro\Model\Config\ThirdPartyPayment $thirdPartyPaymentConfig - * @param \Swarming\SubscribePro\Helper\ThirdPartyPayment $thirdPartyPayment + * @param Session $checkoutSession + * @param Quote $quoteHelper + * @param ThirdPartyPayment $thirdPartyPayment + * @param LoggerInterface $logger */ public function __construct( - \Magento\Checkout\Model\Session $checkoutSession, - \Swarming\SubscribePro\Helper\Quote $quoteHelper, - \Swarming\SubscribePro\Model\Config\ThirdPartyPayment $thirdPartyPaymentConfig, - \Swarming\SubscribePro\Helper\ThirdPartyPayment $thirdPartyPayment, - \Psr\Log\LoggerInterface $logger + Session $checkoutSession, + Quote $quoteHelper, + ThirdPartyPayment $thirdPartyPayment, + LoggerInterface $logger ) { $this->checkoutSession = $checkoutSession; $this->quoteHelper = $quoteHelper; - $this->thirdPartyPaymentConfig = $thirdPartyPaymentConfig; $this->thirdPartyPayment = $thirdPartyPayment; $this->logger = $logger; } diff --git a/phpstan.neon b/phpstan.neon index 817a6fe..1445c09 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,3 +7,4 @@ parameters: - '#Call to an undefined method Magento\\Framework\\App\\RequestInterface\:\:getPostValue\(\)#' - '#Call to an undefined method Magento\\Framework\\App\\RequestInterface\:\:getHeader\(\)#' - '#Call to an undefined method Magento\\Framework\\App\\RequestInterface\:\:getContent\(\)#' + treatPhpDocTypesAsCertain: false