Skip to content

Commit 6afe698

Browse files
committed
PSR-2 refactor
1 parent 6815c86 commit 6afe698

File tree

12 files changed

+73
-75
lines changed

12 files changed

+73
-75
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/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
}

Helper/Data.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
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\FormFieldManager\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_formfieldmanager/general/active';
1212
const XML_CUSTOMER_ATTRIBUTE = 'magepal_formfieldmanager/general/customer_attribute';
1313
const XML_CUSTOMER_ADDRESS_ATTRIBUTE = 'magepal_formfieldmanager/general/customer_address_attribute';
1414

15-
static $ignoreLazyLoad = 0;
16-
15+
public static $ignoreLazyLoad = 0;
1716

1817
/**
1918
* If enabled
2019
*
2120
* @return bool
2221
*/
23-
public function isEnabled() {
22+
public function isEnabled()
23+
{
2424
return $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
2525
}
2626

2727
/**
2828
* Check page type
2929
* @return bool
3030
*/
31-
public function isCustomerEditAdminPage(){
31+
public function isCustomerEditAdminPage()
32+
{
3233
return $this->_request->getFullActionName() === 'customer_index_edit';
3334
}
3435

3536
/**
3637
* Check page type
3738
* @return bool
3839
*/
39-
public function isOrderCreationAdminPage(){
40+
public function isOrderCreationAdminPage()
41+
{
4042
return $this->_request->getFullActionName() === 'sales_order_create_index'
4143
|| $this->_request->getFullActionName() === 'sales_order_create_loadBlock';
4244
}
@@ -45,23 +47,26 @@ public function isOrderCreationAdminPage(){
4547
* Get list of customer attribute to disabled
4648
* @return string|null
4749
*/
48-
public function getCustomerAttribute(){
50+
public function getCustomerAttribute()
51+
{
4952
return $this->scopeConfig->getValue(self::XML_CUSTOMER_ATTRIBUTE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5053
}
5154

5255
/**
5356
* Get list of customer attribute to disabled
5457
* @return string|null
5558
*/
56-
public function getCustomerAddressAttribute(){
59+
public function getCustomerAddressAttribute()
60+
{
5761
return $this->scopeConfig->getValue(self::XML_CUSTOMER_ADDRESS_ATTRIBUTE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
5862
}
5963

6064
/**
6165
* Get Array of customer attribute to disabled
6266
* @return array
6367
*/
64-
public function getCustomerAttributeArray(){
68+
public function getCustomerAttributeArray()
69+
{
6570
$list = $this->getCustomerAttribute();
6671

6772
return empty($list) ? [] : explode(',', $list);
@@ -71,7 +76,8 @@ public function getCustomerAttributeArray(){
7176
* Get Array of customer attribute to disabled
7277
* @return array
7378
*/
74-
public function getCustomerAddressAttributeArray(){
79+
public function getCustomerAddressAttributeArray()
80+
{
7581
$list = $this->getCustomerAddressAttribute();
7682

7783
return empty($list) ? [] : explode(',', $list);
@@ -84,11 +90,12 @@ public function getCustomerAddressAttributeArray(){
8490
* @param string $separator
8591
* @return bool
8692
*/
87-
public function array_path_exists($array, $path, $separator = '/'){
93+
public function array_path_exists($array, $path, $separator = '/')
94+
{
8895
$paths = explode($separator, $path);
8996

90-
foreach($paths as $sub){
91-
if(!is_array($array) || !array_key_exists($sub, $array)){
97+
foreach ($paths as $sub) {
98+
if (!is_array($array) || !array_key_exists($sub, $array)) {
9299
return false;
93100
}
94101

@@ -97,6 +104,4 @@ public function array_path_exists($array, $path, $separator = '/'){
97104

98105
return true;
99106
}
100-
101-
102107
}

Model/Config/Source/AddressAttribute.php

Lines changed: 4 additions & 7 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
namespace MagePal\FormFieldManager\Model\Config\Source;
@@ -19,12 +19,10 @@ class AddressAttribute implements \Magento\Framework\Option\ArrayInterface
1919

2020
public function __construct(
2121
\Magento\Customer\Model\Metadata\FormFactory $customerFormFactory
22-
){
22+
) {
2323
$this->_customerFormFactory = $customerFormFactory;
24-
2524
}
2625

27-
2826
/**
2927
* @return array
3028
*/
@@ -40,11 +38,10 @@ public function toOptionArray()
4038

4139
$ignoreList = ['created_at', 'created_in', 'disable_auto_group_change', 'region', 'region_id', 'postcode'];
4240

43-
foreach($attributes as $attribute){
44-
if(!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)){
41+
foreach ($attributes as $attribute) {
42+
if (!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)) {
4543
$fields[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel()];
4644
}
47-
4845
}
4946

5047
return $fields;

Model/Config/Source/CustomerAttribute.php

Lines changed: 4 additions & 7 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
namespace MagePal\FormFieldManager\Model\Config\Source;
@@ -19,12 +19,10 @@ class CustomerAttribute implements \Magento\Framework\Option\ArrayInterface
1919

2020
public function __construct(
2121
\Magento\Customer\Model\Metadata\FormFactory $customerFormFactory
22-
){
22+
) {
2323
$this->_customerFormFactory = $customerFormFactory;
24-
2524
}
2625

27-
2826
/**
2927
* @return array
3028
*/
@@ -40,11 +38,10 @@ public function toOptionArray()
4038

4139
$ignoreList = ['created_at', 'created_in', 'disable_auto_group_change'];
4240

43-
foreach($attributes as $attribute){
44-
if(!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)){
41+
foreach ($attributes as $attribute) {
42+
if (!$attribute->isRequired() && !in_array($attribute->getAttributeCode(), $ignoreList)) {
4543
$fields[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getStoreLabel()];
4644
}
47-
4845
}
4946

5047
return $fields;
Lines changed: 10 additions & 15 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
namespace MagePal\FormFieldManager\Plugin\Component;
@@ -11,7 +11,6 @@ class AbstractComponentPlugin
1111
/* @var \MagePal\FormFieldManager\Helper\Data */
1212
private $_dataHelper;
1313

14-
1514
/**
1615
* DataProviderPlugin constructor.
1716
*/
@@ -29,35 +28,31 @@ public function __construct(
2928
*/
3029
public function afterGetChildComponents(\Magento\Ui\Component\AbstractComponent $subject, $result)
3130
{
32-
33-
if($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()){
34-
if($subject->getName() == 'customer'){
31+
if ($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
32+
if ($subject->getName() == 'customer') {
3533
$this->hideFields($result, $this->_dataHelper->getCustomerAttributeArray());
36-
}
37-
else if($subject->getName() == 'address'){
34+
} elseif ($subject->getName() == 'address') {
3835
$this->hideFields($result, $this->_dataHelper->getCustomerAddressAttributeArray());
3936
}
4037
}
4138

42-
4339
return $result;
4440
}
4541

4642
/**
4743
* @param $result
4844
* @param $fields
4945
*/
50-
private function hideFields(&$result, $fields){
51-
if(is_array($result)){
52-
foreach($fields as $field){
53-
if(array_key_exists($field, $result)){
54-
46+
private function hideFields(&$result, $fields)
47+
{
48+
if (is_array($result)) {
49+
foreach ($fields as $field) {
50+
if (array_key_exists($field, $result)) {
5551
$temp = $result[$field]->getConfig();
5652
$temp['visible'] = false;
5753
$result[$field]->setConfig($temp);
5854
}
5955
}
60-
6156
}
6257
}
63-
}
58+
}

Plugin/Model/Customer/DataProviderPlugin.php

Lines changed: 4 additions & 5 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

@@ -26,7 +26,6 @@ public function __construct(
2626
$this->timezone = $timezone;
2727
}
2828

29-
3029
/**
3130
* @param \Magento\Customer\Model\Customer\DataProvider $subject
3231
* @param $result
@@ -35,14 +34,14 @@ public function __construct(
3534
public function afterGetData(\Magento\Customer\Model\Customer\DataProvider $subject, $result)
3635
{
3736
//check if dob is hidden and need to change the date format
38-
if($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
37+
if ($this->_dataHelper->isCustomerEditAdminPage() && $this->_dataHelper->isEnabled()) {
3938
if (is_array($result) && in_array('dob', $this->_dataHelper->getCustomerAttributeArray())) {
4039
if ($this->_dataHelper->array_path_exists($result, '1/customer/dob')) {
4140
$result[1]['customer']['dob'] = $this->timezone->date($result[1]['customer']['dob'])->format('m/d/Y');
4241
}
4342
}
4443
}
4544

46-
return $result;
45+
return $result;
4746
}
48-
}
47+
}

0 commit comments

Comments
 (0)