| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 47 |
| 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 |
||
| 76 | public function install( |
||
|
|
|||
| 77 | ModuleDataSetupInterface $setup, |
||
| 78 | ModuleContextInterface $context |
||
| 79 | ) { |
||
| 80 | $setup->startSetup(); |
||
| 81 | |||
| 82 | /** @var CustomerSetup $customerSetup */ |
||
| 83 | $customerSetup = $this->customerSetupFactory->create(); |
||
| 84 | $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); |
||
| 85 | $attributeSetId = $customerEntity->getDefaultAttributeSetId(); |
||
| 86 | |||
| 87 | /** @var $attributeSet AttributeSet */ |
||
| 88 | $attributeSet = $this->attributeSetFactory->create(); |
||
| 89 | $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); |
||
| 90 | |||
| 91 | $useTwoFactorCode = IsUsingTwoFactor::ATTRIBUTE_CODE; |
||
| 92 | |||
| 93 | $customerSetup->addAttribute( |
||
| 94 | 'customer', |
||
| 95 | $useTwoFactorCode, |
||
| 96 | [ |
||
| 97 | 'type' => 'int', |
||
| 98 | 'label' => $useTwoFactorCode, |
||
| 99 | 'input' => 'boolean', |
||
| 100 | 'source' => '', |
||
| 101 | 'required' => true, |
||
| 102 | 'visible' => true, |
||
| 103 | 'position' => 333, |
||
| 104 | 'system' => false, |
||
| 105 | 'backend' => '', |
||
| 106 | ] |
||
| 107 | ); |
||
| 108 | |||
| 109 | $attribute = $customerSetup->getEavConfig()->getAttribute('customer', $useTwoFactorCode)->addData( |
||
| 110 | [ |
||
| 111 | 'attribute_set_id' => $attributeSetId, |
||
| 112 | 'attribute_group_id' => $attributeGroupId, |
||
| 113 | 'is_used_in_grid' => 1, |
||
| 114 | 'is_visible_in_grid' => 1, |
||
| 115 | 'is_filterable_in_grid' => 1, |
||
| 116 | 'is_searchable_in_grid' => 1, |
||
| 117 | 'used_in_forms' => [ |
||
| 118 | 'adminhtml_customer', |
||
| 119 | 'customer_account_create', |
||
| 120 | 'customer_account_edit', |
||
| 121 | ], |
||
| 122 | ] |
||
| 123 | ); |
||
| 124 | $attribute->save(); |
||
| 125 | |||
| 126 | $secretCode = TwoFactorSecret::ATTRIBUTE_CODE; |
||
| 127 | |||
| 128 | $customerSetup->addAttribute( |
||
| 129 | 'customer', |
||
| 130 | $secretCode, |
||
| 131 | [ |
||
| 132 | 'type' => 'varchar', |
||
| 133 | 'label' => $secretCode, |
||
| 134 | 'input' => 'text', |
||
| 135 | 'source' => '', |
||
| 136 | 'required' => false, |
||
| 137 | 'visible' => false, |
||
| 138 | 'position' => 334, |
||
| 139 | 'system' => false, |
||
| 140 | 'backend' => '', |
||
| 141 | ] |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | } |
||
| 145 |