TwoFactorCodeValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validate() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Validator;
13
14
use Da\TwoFA\Exception\InvalidSecretKeyException;
15
use Da\TwoFA\Manager;
16
use Da\User\Contracts\ValidatorInterface;
17
use Da\User\Model\User;
18
19
class TwoFactorCodeValidator implements ValidatorInterface
20
{
21
    protected $user;
22
    protected $code;
23
    protected $cycles;
24
25
    /**
26
     * TwoFactorCodeValidator constructor.
27
     *
28
     * @param User $user
29
     * @param $code
30
     * @param int $cycles
31
     */
32
    public function __construct(User $user, $code, $cycles = 0)
33
    {
34
        $this->user = $user;
35
        $this->code = $code;
36
        $this->cycles = $cycles;
37
    }
38
39
    /**
40
     * @throws InvalidSecretKeyException
41
     * @return bool|int
42
     *
43
     */
44
    public function validate()
45
    {
46
        $manager = new Manager();
47
        return $manager->setCycles($this->cycles)->verify($this->code, $this->user->auth_tf_key);
48
    }
49
}
50