Completed
Push — master ( 479bd3...ba046f )
by Ross
24:36
created

Save::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 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\Controller\Adminhtml\System\Account;
23
24
use Magento\Backend\Controller\Adminhtml\System\Account\Save as OriginalClass;
25
use Rossmitchell\Twofactor\Model\Admin\AdminUser;
26
use Rossmitchell\Twofactor\Model\Admin\Attribute\IsUsingTwoFactor;
27
28
class Save
29
{
30
    /**
31
     * @var AdminUser
32
     */
33
    private $adminUser;
34
    /**
35
     * @var IsUsingTwoFactor
36
     */
37
    private $isUsingTwoFactor;
38
39
    /**
40
     * Save constructor.
41
     *
42
     * @param AdminUser        $adminUser
43
     * @param IsUsingTwoFactor $isUsingTwoFactor
44
     */
45 4
    public function __construct(AdminUser $adminUser, IsUsingTwoFactor $isUsingTwoFactor)
46
    {
47 4
        $this->adminUser = $adminUser;
48 4
        $this->isUsingTwoFactor = $isUsingTwoFactor;
49 4
    }
50
51 4
    public function beforeExecute(OriginalClass $subject)
0 ignored issues
show
introduced by
The use of public non-interface method in ACTION is discouraged.
Loading history...
52
    {
53 4
        $useTwoFactor = $subject->getRequest()->getParam('use_two_factor');
54
55 4
        if (null !== $useTwoFactor) {
56 4
            $this->updateAdminUser($useTwoFactor);
57
        }
58
59 4
        return [];
60
    }
61
62 4
    private function updateAdminUser($value)
63
    {
64 4
        $adminUser = $this->adminUser->getAdminUser();
65 4
        $this->isUsingTwoFactor->setValue($adminUser, $value);
66 4
        $this->adminUser->saveAdminUser($adminUser);
67 4
    }
68
}
69