Passed
Push — master ( aeba21...9e76ce )
by Ross
47:24
created

UseTwoFactor::getSelectedForNo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Block\Customer\Account\Edit;
23
24
use Magento\Customer\Api\Data\CustomerInterface;
25
use Magento\Framework\View\Element\Template;
26
use Magento\Framework\View\Element\Template\Context;
27
use Rossmitchell\Twofactor\Model\Config\Customer as CustomerConfig;
28
use Rossmitchell\Twofactor\Model\Customer\Attribute\IsUsingTwoFactor;
29
use Rossmitchell\Twofactor\Model\Customer\Customer;
30
use Rossmitchell\Twofactor\Model\Customer\UsingTwoFactor;
31
32
class UseTwoFactor extends Template
33
{
34
    /**
35
     * @var IsUsingTwoFactor
36
     */
37
    private $isUsingTwoFactor;
38
    /**
39
     * @var Customer
40
     */
41
    private $customerGetter;
42
    /**
43
     * @var CustomerConfig
44
     */
45
    private $customerConfig;
46
47
    /**
48
     * UseTwoFactor constructor.
49
     *
50
     * @param Context          $context
51
     * @param IsUsingTwoFactor $isUsingTwoFactor
52
     * @param Customer         $customerGetter
53
     * @param CustomerConfig   $customerConfig
54
     * @param array            $data
55
     */
56 8 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
        Context $context,
58
        IsUsingTwoFactor $isUsingTwoFactor,
59
        Customer $customerGetter,
60
        CustomerConfig $customerConfig,
61
        array $data = []
62
    ) {
63 8
        parent::__construct($context, $data);
64 8
        $this->isUsingTwoFactor = $isUsingTwoFactor;
65 8
        $this->customerGetter   = $customerGetter;
66 8
        $this->customerConfig = $customerConfig;
67 8
    }
68
69 8
    public function shouldBlockBeDisplayed()
70
    {
71 8
        return ($this->customerConfig->isTwoFactorEnabled() == true);
72
    }
73
74 6
    public function getCustomer()
75
    {
76 6
        return $this->customerGetter->getCustomer();
77
    }
78
79 6
    public function isUsingTwoFactor(CustomerInterface $customer)
80
    {
81 6
        if ($this->isUsingTwoFactor->hasValue($customer) === false) {
82
            return false;
83
        }
84
85 6
        return ($this->isUsingTwoFactor->getValue($customer) == true);
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
86
    }
87
88 6
    public function getSelectedForYes(CustomerInterface $customer)
89
    {
90 6
        return $this->getSelectedSnippet($customer, true);
91
    }
92
93 6
    public function getSelectedForNo(CustomerInterface $customer)
94
    {
95 6
        return $this->getSelectedSnippet($customer, false);
96
    }
97
98 6
    private function getSelectedSnippet(CustomerInterface $customer, $condition)
99
    {
100 6
        $html = '';
101 6
        if ($this->isUsingTwoFactor($customer) === $condition) {
102 6
            $html = ' selected="selected"';
103 3
        }
104
105 6
        return $html;
106
    }
107
}
108