Passed
Push — master ( 492849...8ad597 )
by Ross
02:52
created

Form   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B beforeSetForm() 0 24 1
1
<?php
2
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
5
 *
6
 * This file is part of Rossmitchell/Twofactor.
7
 *
8
 * Rossmitchell/Twofactor is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace Rossmitchell\Twofactor\Plugin\Magento\Backend\Block\System\Account\Edit;
23
24
use Magento\Backend\Block\System\Account\Edit\Form as OriginalClass;
25
use Magento\Framework\Data\Form as OriginalForm;
26
use Rossmitchell\Twofactor\Model\Admin\AdminUser;
27
28
class Form
29
{
30
    /**
31
     * @var AdminUser
32
     */
33
    private $adminUser;
34
35
    /**
36
     * Form constructor.
37
     *
38
     * @param AdminUser $adminUser
39
     */
40
    public function __construct(AdminUser $adminUser)
41
    {
42
        $this->adminUser = $adminUser;
43
    }
44
45
    public function beforeSetForm(OriginalClass $subject, OriginalForm $result)
46
    {
47
        $form     = $result;
48
        $fieldSet = $form->getElement('base_fieldset');
49
        $fieldSet->addField(
50
            'use_two_factor',
51
            'select',
52
            [
53
                'name' => 'use_two_factor',
54
                'label' => __('Use Two Factor for this account'),
55
                'title' => __('Use Two Factor for this account'),
56
                'values' => [['value' => '0', 'label' => 'No'], ['value' => '1', 'label' => 'Yes']],
57
                'class' => 'select',
58
            ]
59
        );
60
61
        $user = $this->adminUser->getAdminUser();
62
        $user->unsetData('password');
63
        $userData = $user->getData();
64
        unset($userData[OriginalClass::IDENTITY_VERIFICATION_PASSWORD_FIELD]);
65
        $form->setValues($userData);
66
67
        return [$form];
68
    }
69
}
70