From f0af7c5ce7092f324b04d50c462696caa5ad93a3 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Sun, 14 Apr 2019 21:57:46 -0400 Subject: [PATCH] Code refactor --- .../System/Config/Form/Composer/Version.php | 56 ++++++++++++------- .../System/Config/Form/Module/Version.php | 34 +++++++---- Helper/Data.php | 13 ++++- Plugin/Model/SubscriberPlugin.php | 26 +++++---- composer.json | 4 +- 5 files changed, 87 insertions(+), 46 deletions(-) diff --git a/Block/Adminhtml/System/Config/Form/Composer/Version.php b/Block/Adminhtml/System/Config/Form/Composer/Version.php index 67748f8..be5068b 100644 --- a/Block/Adminhtml/System/Config/Form/Composer/Version.php +++ b/Block/Adminhtml/System/Config/Form/Composer/Version.php @@ -7,34 +7,52 @@ namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer; -class Version extends \Magento\Config\Block\System\Config\Form\Field +use Exception; +use Magento\Backend\Block\Template\Context; +use Magento\Config\Block\System\Config\Form\Field; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Component\ComponentRegistrarInterface; +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem\Directory\ReadFactory; +use Magento\Framework\Phrase; + +/** + * Class Version + * @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer + */ +class Version extends Field { /** - * @var \Magento\Framework\App\DeploymentConfig + * @var DeploymentConfig */ protected $deploymentConfig; /** - * @var \Magento\Framework\Component\ComponentRegistrarInterface + * @var ComponentRegistrarInterface */ protected $componentRegistrar; /** - * @var \Magento\Framework\Filesystem\Directory\ReadFactory + * @var ReadFactory */ protected $readFactory; /** - * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig - * @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar - * @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory + * Version constructor. + * @param Context $context + * @param DeploymentConfig $deploymentConfig + * @param ComponentRegistrarInterface $componentRegistrar + * @param ReadFactory $readFactory + * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\App\DeploymentConfig $deploymentConfig, - \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar, - \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, + Context $context, + DeploymentConfig $deploymentConfig, + ComponentRegistrarInterface $componentRegistrar, + ReadFactory $readFactory, array $data = [] ) { $this->deploymentConfig = $deploymentConfig; @@ -46,11 +64,11 @@ public function __construct( /** * Render button * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + public function render(AbstractElement $element) { // Remove scope label $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); @@ -60,11 +78,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele /** * Return element html * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) + protected function _getElementHtml(AbstractElement $element) { return 'v' . $this->getVersion(); } @@ -93,12 +111,12 @@ public function getModuleName() * Get module composer version * * @param $moduleName - * @return \Magento\Framework\Phrase|string|void + * @return Phrase|string|void */ public function getComposerVersion($moduleName) { $path = $this->componentRegistrar->getPath( - \Magento\Framework\Component\ComponentRegistrar::MODULE, + ComponentRegistrar::MODULE, $moduleName ); @@ -110,7 +128,7 @@ public function getComposerVersion($moduleName) $data = json_decode($composerJsonData); return !empty($data->version) ? $data->version : __('Unknown'); } - } catch (\Exception $e) { + } catch (Exception $e) { // } diff --git a/Block/Adminhtml/System/Config/Form/Module/Version.php b/Block/Adminhtml/System/Config/Form/Module/Version.php index 3300eab..fbe67ef 100644 --- a/Block/Adminhtml/System/Config/Form/Module/Version.php +++ b/Block/Adminhtml/System/Config/Form/Module/Version.php @@ -7,22 +7,34 @@ namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module; -class Version extends \Magento\Config\Block\System\Config\Form\Field +use Magento\Backend\Block\Template\Context; +use Magento\Config\Block\System\Config\Form\Field; +use Magento\Framework\Data\Form\Element\AbstractElement; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Module\ModuleListInterface; + +/** + * Class Version + * @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module + */ +class Version extends Field { /** - * @var \Magento\Framework\Module\ModuleListInterface + * @var ModuleListInterface */ protected $_moduleList; + /** - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Module\ModuleListInterface $moduleList + * Version constructor. + * @param Context $context + * @param ModuleListInterface $moduleList * @param array $data */ public function __construct( - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Module\ModuleListInterface $moduleList, + Context $context, + ModuleListInterface $moduleList, array $data = [] ) { parent::__construct($context, $data); @@ -32,11 +44,11 @@ public function __construct( /** * Render button * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + public function render(AbstractElement $element) { // Remove scope label $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); @@ -46,11 +58,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele /** * Return element html * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @param AbstractElement $element * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) + protected function _getElementHtml(AbstractElement $element) { return 'v' . $this->getVersion(); } diff --git a/Helper/Data.php b/Helper/Data.php index 11956a2..be99db5 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -3,11 +3,18 @@ * Copyright © MagePal LLC. All rights reserved. * See COPYING.txt for license details. * http://www.magepal.com | support@magepal.com -*/ + */ namespace MagePal\NewsletterSignupEmail\Helper; -class Data extends \Magento\Framework\App\Helper\AbstractHelper +use Magento\Framework\App\Helper\AbstractHelper; +use Magento\Store\Model\ScopeInterface; + +/** + * Class Data + * @package MagePal\NewsletterSignupEmail\Helper + */ +class Data extends AbstractHelper { const XML_PATH_ACTIVE = 'newsletter_signup_email/general/active'; @@ -20,7 +27,7 @@ public function isEnabled() { return !$this->scopeConfig->isSetFlag( self::XML_PATH_ACTIVE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ScopeInterface::SCOPE_STORE ); } } diff --git a/Plugin/Model/SubscriberPlugin.php b/Plugin/Model/SubscriberPlugin.php index ca5327f..116c2b7 100644 --- a/Plugin/Model/SubscriberPlugin.php +++ b/Plugin/Model/SubscriberPlugin.php @@ -4,49 +4,53 @@ * See COPYING.txt for license details. * http://www.magepal.com | support@magepal.com */ + namespace MagePal\NewsletterSignupEmail\Plugin\Model; +use Magento\Newsletter\Model\Subscriber; +use MagePal\NewsletterSignupEmail\Helper\Data; + class SubscriberPlugin { - /** @var \MagePal\NewsletterSignupEmail\Helper\Data */ + /** @var Data */ protected $helper; public function __construct( - \MagePal\NewsletterSignupEmail\Helper\Data $helper + Data $helper ) { $this->helper = $helper; } /** - * @param \Magento\Newsletter\Model\Subscriber $subject + * @param Subscriber $subject * @param callable $proceed */ - public function aroundSendUnsubscriptionEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed) + public function aroundSendUnsubscriptionEmail(Subscriber $subject, callable $proceed) { - if($this->helper->isEnabled()){ + if ($this->helper->isEnabled()) { $proceed(); } } /** - * @param \Magento\Newsletter\Model\Subscriber $subject + * @param Subscriber $subject * @param callable $proceed */ - public function aroundSendConfirmationRequestEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed) + public function aroundSendConfirmationRequestEmail(Subscriber $subject, callable $proceed) { - if($this->helper->isEnabled()){ + if ($this->helper->isEnabled()) { $proceed(); } } /** - * @param \Magento\Newsletter\Model\Subscriber $subject + * @param Subscriber $subject * @param callable $proceed */ - public function aroundSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed) + public function aroundSendConfirmationSuccessEmail(Subscriber $subject, callable $proceed) { - if($this->helper->isEnabled()){ + if ($this->helper->isEnabled()) { $proceed(); } } diff --git a/composer.json b/composer.json index e8c5cdc..2388290 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ ], "require": { "php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.1.3|~7.2.0", - "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.0", + "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*", "magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*", "magento/module-newsletter": "*" }, "type": "magento2-module", - "version": "1.1.1", + "version": "1.1.2", "autoload": { "files": [ "registration.php"