| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 67 | public function install( |
||
|
|
|||
| 68 | ModuleDataSetupInterface $setup, |
||
| 69 | ModuleContextInterface $context |
||
| 70 | ) { |
||
| 71 | /** @var CustomerSetup $customerSetup */ |
||
| 72 | $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); |
||
| 73 | $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); |
||
| 74 | $attributeSetId = $customerEntity->getDefaultAttributeSetId(); |
||
| 75 | |||
| 76 | /** @var $attributeSet AttributeSet */ |
||
| 77 | $attributeSet = $this->attributeSetFactory->create(); |
||
| 78 | $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); |
||
| 79 | |||
| 80 | $useTwoFactorCode = IsUsingTwoFactor::ATTRIBUTE_CODE; |
||
| 81 | |||
| 82 | $customerSetup->addAttribute( |
||
| 83 | 'customer', |
||
| 84 | $useTwoFactorCode, |
||
| 85 | [ |
||
| 86 | 'type' => 'int', |
||
| 87 | 'label' => $useTwoFactorCode, |
||
| 88 | 'input' => 'boolean', |
||
| 89 | 'source' => '', |
||
| 90 | 'required' => true, |
||
| 91 | 'visible' => true, |
||
| 92 | 'position' => 333, |
||
| 93 | 'system' => false, |
||
| 94 | 'backend' => '', |
||
| 95 | ] |
||
| 96 | ); |
||
| 97 | |||
| 98 | $attribute = $customerSetup->getEavConfig()->getAttribute('customer', $useTwoFactorCode)->addData( |
||
| 99 | [ |
||
| 100 | 'attribute_set_id' => $attributeSetId, |
||
| 101 | 'attribute_group_id' => $attributeGroupId, |
||
| 102 | 'used_in_forms' => [ |
||
| 103 | 'adminhtml_customer', |
||
| 104 | 'customer_account_create', |
||
| 105 | 'customer_account_edit', |
||
| 106 | ], |
||
| 107 | ] |
||
| 108 | ); |
||
| 109 | $attribute->save(); |
||
| 110 | |||
| 111 | $secretCode = TwoFactorSecret::ATTRIBUTE_CODE; |
||
| 112 | |||
| 113 | $customerSetup->addAttribute( |
||
| 114 | 'customer', |
||
| 115 | $secretCode, |
||
| 116 | [ |
||
| 117 | 'type' => 'varchar', |
||
| 118 | 'label' => $secretCode, |
||
| 119 | 'input' => 'text', |
||
| 120 | 'source' => '', |
||
| 121 | 'required' => false, |
||
| 122 | 'visible' => false, |
||
| 123 | 'position' => 334, |
||
| 124 | 'system' => false, |
||
| 125 | 'backend' => '', |
||
| 126 | ] |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | } |
||
| 130 |