Skip to content

Commit f0af7c5

Browse files
committed
Code refactor
1 parent 93d2e48 commit f0af7c5

File tree

5 files changed

+87
-46
lines changed

5 files changed

+87
-46
lines changed

Block/Adminhtml/System/Config/Form/Composer/Version.php

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,52 @@
77

88
namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer;
99

10-
class Version extends \Magento\Config\Block\System\Config\Form\Field
10+
use Exception;
11+
use Magento\Backend\Block\Template\Context;
12+
use Magento\Config\Block\System\Config\Form\Field;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\Component\ComponentRegistrar;
15+
use Magento\Framework\Component\ComponentRegistrarInterface;
16+
use Magento\Framework\Data\Form\Element\AbstractElement;
17+
use Magento\Framework\Exception\LocalizedException;
18+
use Magento\Framework\Filesystem\Directory\ReadFactory;
19+
use Magento\Framework\Phrase;
20+
21+
/**
22+
* Class Version
23+
* @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer
24+
*/
25+
class Version extends Field
1126
{
1227

1328
/**
14-
* @var \Magento\Framework\App\DeploymentConfig
29+
* @var DeploymentConfig
1530
*/
1631
protected $deploymentConfig;
1732

1833
/**
19-
* @var \Magento\Framework\Component\ComponentRegistrarInterface
34+
* @var ComponentRegistrarInterface
2035
*/
2136
protected $componentRegistrar;
2237

2338
/**
24-
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
39+
* @var ReadFactory
2540
*/
2641
protected $readFactory;
2742

2843
/**
29-
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
30-
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
31-
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
44+
* Version constructor.
45+
* @param Context $context
46+
* @param DeploymentConfig $deploymentConfig
47+
* @param ComponentRegistrarInterface $componentRegistrar
48+
* @param ReadFactory $readFactory
49+
* @param array $data
3250
*/
3351
public function __construct(
34-
\Magento\Backend\Block\Template\Context $context,
35-
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
36-
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
37-
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
52+
Context $context,
53+
DeploymentConfig $deploymentConfig,
54+
ComponentRegistrarInterface $componentRegistrar,
55+
ReadFactory $readFactory,
3856
array $data = []
3957
) {
4058
$this->deploymentConfig = $deploymentConfig;
@@ -46,11 +64,11 @@ public function __construct(
4664
/**
4765
* Render button
4866
*
49-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
67+
* @param AbstractElement $element
5068
* @return string
51-
* @throws \Magento\Framework\Exception\LocalizedException
69+
* @throws LocalizedException
5270
*/
53-
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
71+
public function render(AbstractElement $element)
5472
{
5573
// Remove scope label
5674
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
@@ -60,11 +78,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
6078
/**
6179
* Return element html
6280
*
63-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
81+
* @param AbstractElement $element
6482
* @return string
6583
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6684
*/
67-
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
85+
protected function _getElementHtml(AbstractElement $element)
6886
{
6987
return 'v' . $this->getVersion();
7088
}
@@ -93,12 +111,12 @@ public function getModuleName()
93111
* Get module composer version
94112
*
95113
* @param $moduleName
96-
* @return \Magento\Framework\Phrase|string|void
114+
* @return Phrase|string|void
97115
*/
98116
public function getComposerVersion($moduleName)
99117
{
100118
$path = $this->componentRegistrar->getPath(
101-
\Magento\Framework\Component\ComponentRegistrar::MODULE,
119+
ComponentRegistrar::MODULE,
102120
$moduleName
103121
);
104122

@@ -110,7 +128,7 @@ public function getComposerVersion($moduleName)
110128
$data = json_decode($composerJsonData);
111129
return !empty($data->version) ? $data->version : __('Unknown');
112130
}
113-
} catch (\Exception $e) {
131+
} catch (Exception $e) {
114132
//
115133
}
116134

Block/Adminhtml/System/Config/Form/Module/Version.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,34 @@
77

88
namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module;
99

10-
class Version extends \Magento\Config\Block\System\Config\Form\Field
10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Config\Block\System\Config\Form\Field;
12+
use Magento\Framework\Data\Form\Element\AbstractElement;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Module\ModuleListInterface;
15+
16+
/**
17+
* Class Version
18+
* @package MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module
19+
*/
20+
class Version extends Field
1121
{
1222

1323
/**
14-
* @var \Magento\Framework\Module\ModuleListInterface
24+
* @var ModuleListInterface
1525
*/
1626
protected $_moduleList;
1727

28+
1829
/**
19-
* @param \Magento\Backend\Block\Template\Context $context
20-
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
30+
* Version constructor.
31+
* @param Context $context
32+
* @param ModuleListInterface $moduleList
2133
* @param array $data
2234
*/
2335
public function __construct(
24-
\Magento\Backend\Block\Template\Context $context,
25-
\Magento\Framework\Module\ModuleListInterface $moduleList,
36+
Context $context,
37+
ModuleListInterface $moduleList,
2638
array $data = []
2739
) {
2840
parent::__construct($context, $data);
@@ -32,11 +44,11 @@ public function __construct(
3244
/**
3345
* Render button
3446
*
35-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
47+
* @param AbstractElement $element
3648
* @return string
37-
* @throws \Magento\Framework\Exception\LocalizedException
49+
* @throws LocalizedException
3850
*/
39-
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
51+
public function render(AbstractElement $element)
4052
{
4153
// Remove scope label
4254
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
@@ -46,11 +58,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
4658
/**
4759
* Return element html
4860
*
49-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
61+
* @param AbstractElement $element
5062
* @return string
5163
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5264
*/
53-
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
65+
protected function _getElementHtml(AbstractElement $element)
5466
{
5567
return 'v' . $this->getVersion();
5668
}

Helper/Data.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
* Copyright © MagePal LLC. All rights reserved.
44
* See COPYING.txt for license details.
55
* http://www.magepal.com | [email protected]
6-
*/
6+
*/
77

88
namespace MagePal\NewsletterSignupEmail\Helper;
99

10-
class Data extends \Magento\Framework\App\Helper\AbstractHelper
10+
use Magento\Framework\App\Helper\AbstractHelper;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
/**
14+
* Class Data
15+
* @package MagePal\NewsletterSignupEmail\Helper
16+
*/
17+
class Data extends AbstractHelper
1118
{
1219
const XML_PATH_ACTIVE = 'newsletter_signup_email/general/active';
1320

@@ -20,7 +27,7 @@ public function isEnabled()
2027
{
2128
return !$this->scopeConfig->isSetFlag(
2229
self::XML_PATH_ACTIVE,
23-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
30+
ScopeInterface::SCOPE_STORE
2431
);
2532
}
2633
}

Plugin/Model/SubscriberPlugin.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,53 @@
44
* See COPYING.txt for license details.
55
* http://www.magepal.com | [email protected]
66
*/
7+
78
namespace MagePal\NewsletterSignupEmail\Plugin\Model;
89

10+
use Magento\Newsletter\Model\Subscriber;
11+
use MagePal\NewsletterSignupEmail\Helper\Data;
12+
913
class SubscriberPlugin
1014
{
1115

12-
/** @var \MagePal\NewsletterSignupEmail\Helper\Data */
16+
/** @var Data */
1317
protected $helper;
1418

1519
public function __construct(
16-
\MagePal\NewsletterSignupEmail\Helper\Data $helper
20+
Data $helper
1721
) {
1822
$this->helper = $helper;
1923
}
2024

2125
/**
22-
* @param \Magento\Newsletter\Model\Subscriber $subject
26+
* @param Subscriber $subject
2327
* @param callable $proceed
2428
*/
25-
public function aroundSendUnsubscriptionEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
29+
public function aroundSendUnsubscriptionEmail(Subscriber $subject, callable $proceed)
2630
{
27-
if($this->helper->isEnabled()){
31+
if ($this->helper->isEnabled()) {
2832
$proceed();
2933
}
3034
}
3135

3236
/**
33-
* @param \Magento\Newsletter\Model\Subscriber $subject
37+
* @param Subscriber $subject
3438
* @param callable $proceed
3539
*/
36-
public function aroundSendConfirmationRequestEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
40+
public function aroundSendConfirmationRequestEmail(Subscriber $subject, callable $proceed)
3741
{
38-
if($this->helper->isEnabled()){
42+
if ($this->helper->isEnabled()) {
3943
$proceed();
4044
}
4145
}
4246

4347
/**
44-
* @param \Magento\Newsletter\Model\Subscriber $subject
48+
* @param Subscriber $subject
4549
* @param callable $proceed
4650
*/
47-
public function aroundSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
51+
public function aroundSendConfirmationSuccessEmail(Subscriber $subject, callable $proceed)
4852
{
49-
if($this->helper->isEnabled()){
53+
if ($this->helper->isEnabled()) {
5054
$proceed();
5155
}
5256
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
],
2525
"require": {
2626
"php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0|~7.1.3|~7.2.0",
27-
"magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.0",
27+
"magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*",
2828
"magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*",
2929
"magento/module-newsletter": "*"
3030
},
3131
"type": "magento2-module",
32-
"version": "1.1.1",
32+
"version": "1.1.2",
3333
"autoload": {
3434
"files": [
3535
"registration.php"

0 commit comments

Comments
 (0)