OtpForm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 49
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 1
A rules() 0 6 1
A verify() 0 10 2
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-mfa
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\mfa;
9
10
use Yii;
11
12
use yii\base\Model;
13
14
/**
15
 * Class OtpForm
16
 *
17
 * @author Vuong Minh <[email protected]>
18
 * @since 1.0.0
19
 */
20
class OtpForm extends Model
21
{
22
23
    use EnsureUserBehaviorAttachedTrait;
24
25
    /**
26
     * @var string an otp submit from end user
27
     */
28
    public $otp;
29
30
    /**
31
     * @inheritDoc
32
     * @throws \yii\base\InvalidConfigException
33
     */
34 3
    public function init()
35
    {
36 3
        $this->ensureUserBehaviorAttached();
37
38 3
        parent::init();
39 3
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44 2
    public function rules()
45
    {
46
        return [
47 2
            [['otp'], 'required']
48
        ];
49
    }
50
51
    /**
52
     * Verify an otp is valid with current logged in user
53
     *
54
     * @return bool weather an otp property is valid.
55
     */
56 2
    public function verify()
57
    {
58 2
        if (!$this->user->validateOtpByIdentityLoggedIn($this->otp)) {
59 1
            $this->addError('otp', Yii::t('app', 'Otp is invalid!'));
60
61 1
            return false;
62
        } else {
63 1
            return true;
64
        }
65
    }
66
67
68
}
69