Skip to content

Commit f79e186

Browse files
committed
PSR-2 refactor
1 parent d689a3a commit f79e186

File tree

10 files changed

+62
-79
lines changed

10 files changed

+62
-79
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2017 MagePal LLC. All rights reserved.
3+
* Copyright © MagePal LLC. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -55,7 +55,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
5555
return parent::render($element);
5656
}
5757

58-
5958
/**
6059
* Return element html
6160
*
@@ -68,13 +67,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
6867
return 'v' . $this->getVersion();
6968
}
7069

71-
7270
/**
7371
* Get Module version number
7472
*
7573
* @return string
7674
*/
77-
public function getVersion(){
75+
public function getVersion()
76+
{
7877
return $this->getComposerVersion($this->getModuleName());
7978
}
8079

@@ -101,21 +100,18 @@ public function getComposerVersion($moduleName)
101100
$moduleName
102101
);
103102

104-
try{
103+
try {
105104
$directoryRead = $this->readFactory->create($path);
106105
$composerJsonData = $directoryRead->readFile('composer.json');
107106

108-
if($composerJsonData){
107+
if ($composerJsonData) {
109108
$data = json_decode($composerJsonData);
110109
return !empty($data->version) ? $data->version : __('Unknown');
111110
}
112-
113-
}
114-
catch (\Exception $e){
111+
} catch (\Exception $e) {
115112
//
116113
}
117114

118115
return 'Unknown';
119-
120116
}
121117
}

Block/Adminhtml/System/Config/Form/Field/MiscScript.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22
/**
3-
* Copyright © 2017 MagePal LLC. All rights reserved.
3+
* Copyright © MagePal LLC. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

77
namespace MagePal\CheckoutSuccessMiscScript\Block\Adminhtml\System\Config\Form\Field;
88

99
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
10+
1011
/**
1112
* Class Locations Backend system config array field renderer
1213
*/
@@ -23,13 +24,11 @@ class MiscScript extends AbstractFieldArray
2324
*/
2425
protected $helper;
2526

26-
2727
public function __construct(
2828
\Magento\Backend\Block\Template\Context $context,
2929
\MagePal\CheckoutSuccessMiscScript\Helper\Data $helper,
3030
array $data = []
31-
)
32-
{
31+
) {
3332
$this->helper = $helper;
3433
parent::__construct($context, $data);
3534
}
@@ -71,10 +70,11 @@ protected function _construct()
7170
parent::_construct();
7271
}
7372

74-
public function getTemplateButtonList(){
73+
public function getTemplateButtonList()
74+
{
7575
$html = '';
7676

77-
foreach ($this->helper->getTemplateVariableKey() as $key){
77+
foreach ($this->helper->getTemplateVariableKey() as $key) {
7878
$html .= '<button style="margin:3px;" data-mage-init=\\\'{"checkoutSuccessMiscScript":{"textareaId":"<%- _id %>_scripts"}}\\\' type="button">' . $key . '</button>';
7979
}
8080

@@ -112,7 +112,7 @@ public function renderCellTemplate($columnName)
112112
$inputName = $this->_getCellInputElementName($columnName);
113113

114114
if ($column['renderer']) {
115-
return str_replace(array("\n", "\t", "\r"), '', $column['renderer']->setInputName(
115+
return str_replace(["\n", "\t", "\r"], '', $column['renderer']->setInputName(
116116
$inputName
117117
)->setInputId(
118118
$this->_getCellInputElementId('<%- _id %>', $columnName)
@@ -123,7 +123,7 @@ public function renderCellTemplate($columnName)
123123
)->toHtml());
124124
}
125125

126-
if($column['type'] == 'text'){
126+
if ($column['type'] == 'text') {
127127
return '<input type="' . $column['type'] . '" id="' . $this->_getCellInputElementId(
128128
'<%- _id %>',
129129
$columnName
@@ -143,8 +143,7 @@ public function renderCellTemplate($columnName)
143143
) ? $column['class'] : 'input-text') . '"' . (isset(
144144
$column['style']
145145
) ? ' style="' . $column['style'] . '"' : '') . '/>';
146-
}
147-
else if($column['type'] == 'checkbox'){
146+
} elseif ($column['type'] == 'checkbox') {
148147
return '<input type="' . $column['type'] . '" id="' . $this->_getCellInputElementId(
149148
'<%- _id %>',
150149
$columnName
@@ -164,8 +163,7 @@ public function renderCellTemplate($columnName)
164163
) ? $column['class'] : 'input-text') . '"' . (isset(
165164
$column['style']
166165
) ? ' style="' . $column['style'] . '"' : '') . '/>';
167-
}
168-
else{
166+
} else {
169167
return '<textarea id="' . $this->_getCellInputElementId(
170168
'<%- _id %>',
171169
$columnName
@@ -184,6 +182,5 @@ public function renderCellTemplate($columnName)
184182
$column['style']
185183
) ? ' style="' . $column['style'] . '"' : '') . '><%- ' . $columnName . ' %></textarea>';
186184
}
187-
188185
}
189186
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2017 MagePal LLC. All rights reserved.
3+
* Copyright © MagePal LLC. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -41,7 +41,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
4141
return parent::render($element);
4242
}
4343

44-
4544
/**
4645
* Return element html
4746
*
@@ -54,13 +53,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
5453
return 'v' . $this->getVersion();
5554
}
5655

57-
5856
/**
5957
* Get Module version number
6058
*
6159
* @return string
6260
*/
63-
public function getVersion(){
61+
public function getVersion()
62+
{
6463
$moduleInfo = $this->_moduleList->getOne($this->getModuleName());
6564
return $moduleInfo['setup_version'];
6665
}

Block/Checkout/Success.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Success extends Template
2828

2929
protected $order;
3030

31-
3231
/**
3332
* @param Context $context
3433
* @param \MagePal\CheckoutSuccessMiscScript\Helper\Data $helper
@@ -49,24 +48,21 @@ public function __construct(
4948
parent::__construct($context, $data);
5049
}
5150

52-
53-
5451
protected function _toHtml()
5552
{
56-
if(!$this->helper->isEnabled()){
53+
if (!$this->helper->isEnabled()) {
5754
return '';
5855
}
5956

6057
return parent::_toHtml();
6158
}
6259

63-
6460
/**
6561
* @return \Magento\Sales\Api\Data\OrderInterface
6662
*/
6763
protected function getOrder()
6864
{
69-
if(!$this->order){
65+
if (!$this->order) {
7066
$this->order = $this->orderRepository->get($this->checkoutSession->getLastOrderId());
7167
}
7268

@@ -77,17 +73,17 @@ protected function getOrder()
7773
* @param $order
7874
* @return $this
7975
*/
80-
public function setOrder($order){
76+
public function setOrder($order)
77+
{
8178
$this->order = $order;
8279
return $this;
8380
}
8481

85-
8682
/**
8783
* @return array
8884
*/
89-
protected function getTemplateArray(){
90-
85+
protected function getTemplateArray()
86+
{
9187
$order = $this->getOrder();
9288

9389
$this->helper->setVariableData('order_id', $order->getIncrementId());
@@ -99,15 +95,14 @@ protected function getTemplateArray(){
9995
$this->helper->setVariableData('discount', $this->helper->formatPrice($order->getDiscountAmount()));
10096

10197
return $this->helper->getTemplateVariable();
102-
10398
}
10499

105-
106100
/**
107101
* @param $string
108102
* @return mixed
109103
*/
110-
protected function processTemplate($string){
104+
protected function processTemplate($string)
105+
{
111106
$template = $this->getTemplateArray();
112107

113108
return str_replace(array_keys($template), array_values($template), $string);
@@ -122,19 +117,18 @@ public function getActiveScripts()
122117

123118
$scripts = $this->helper->getScripts();
124119

125-
if(is_array($scripts)){
120+
if (is_array($scripts)) {
126121
foreach ($scripts as $script) {
127-
if(
122+
if (
128123
array_key_exists('is_enabled', $script)
129124
&& $script['is_enabled'] == 'checked'
130125
&& array_key_exists('scripts', $script)
131-
){
126+
) {
132127
$html .= $script['scripts'];
133128
}
134129
}
135130
}
136131

137132
return $this->processTemplate($html);
138133
}
139-
140-
}
134+
}

Helper/Data.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace MagePal\CheckoutSuccessMiscScript\Helper;
88

9-
class Data extends \Magento\Framework\App\Helper\AbstractHelper {
10-
9+
class Data extends \Magento\Framework\App\Helper\AbstractHelper
10+
{
1111
const XML_PATH_ACTIVE = 'magepal_checkout/misc_script/active';
1212

1313
protected $variables =[
@@ -45,7 +45,8 @@ public function __construct(
4545
*
4646
* @return bool
4747
*/
48-
public function isEnabled() {
48+
public function isEnabled()
49+
{
4950
return $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5051
}
5152

@@ -54,7 +55,8 @@ public function isEnabled() {
5455
*
5556
* @return bool
5657
*/
57-
public function getScripts() {
58+
public function getScripts()
59+
{
5860
$json = $this->scopeConfig->getValue('magepal_checkout/misc_script/scripts', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5961
return $this->jsonHelper->jsonDecode($json);
6062
}
@@ -65,40 +67,41 @@ public function getScripts() {
6567
* @param $price
6668
* @return float
6769
*/
68-
public function formatPrice($price){
70+
public function formatPrice($price)
71+
{
6972
return (float)sprintf('%.2F', $price);
7073
}
7174

72-
73-
public function getVariables(){
75+
public function getVariables()
76+
{
7477
return $this->variables;
7578
}
7679

77-
78-
79-
public function setVariableData($key, $value){
80-
if(array_key_exists($key, $this->variables)){
80+
public function setVariableData($key, $value)
81+
{
82+
if (array_key_exists($key, $this->variables)) {
8183
$this->variables[$key] = $value;
8284
}
8385

8486
return $this;
8587
}
8688

87-
public function getTemplateVariableKey(){
89+
public function getTemplateVariableKey()
90+
{
8891
$keys = [];
8992

90-
foreach ($this->getVariables() as $key => $val){
93+
foreach ($this->getVariables() as $key => $val) {
9194
$keys[] = self::TEMPLATE_START . $key . self::TEMPLATE_END;
9295
}
9396

9497
return $keys;
9598
}
9699

97-
98-
public function getTemplateVariable(){
100+
public function getTemplateVariable()
101+
{
99102
$values = [];
100103

101-
foreach ($this->getVariables() as $key => $val){
104+
foreach ($this->getVariables() as $key => $val) {
102105
$values[self::TEMPLATE_START . $key . self::TEMPLATE_END] = $val;
103106
}
104107

0 commit comments

Comments
 (0)