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

IsUsingTwoFactor::hasValue()   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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
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\Model\Customer\Attribute;
23
24
class IsUsingTwoFactor
25
{
26
    const ATTRIBUTE_CODE = 'use_two_factor_authentication';
27
28
    /**
29
     * @var Getter
30
     */
31
    private $getter;
32
    /**
33
     * @var Setter
34
     */
35
    private $setter;
36
37
    /**
38
     * IsUsingTwoFactor constructor.
39
     *
40
     * @param Getter $getter
41
     * @param Setter $setter
42
     */
43 54
    public function __construct(Getter $getter, Setter $setter)
44
    {
45 54
        $this->getter = $getter;
46 54
        $this->setter = $setter;
47 54
    }
48
49 26
    public function getValue($customer)
50
    {
51 26
        if ($this->hasValue($customer) === false) {
52
            return false;
53
        }
54
55 26
        $value = $this->getter->getValue($customer, self::ATTRIBUTE_CODE);
56
57 26
        return ($value == true);
58
    }
59
60
    public function setValue($customer, $value)
61
    {
62
        $this->setter->setValue($customer, self::ATTRIBUTE_CODE, $value);
63
    }
64
65 26
    public function hasValue($customer)
66
    {
67 26
        return $this->getter->hasValue($customer, self::ATTRIBUTE_CODE);
68
    }
69
}
70