Identity   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findIdentity() 0 8 2
A findIdentityByAccessToken() 0 4 1
A getId() 0 4 1
A getAuthKey() 0 4 1
A validateAuthKey() 0 4 1
A getMfaSecretKey() 0 4 1
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\test\unit\mfa;
9
10
use yii\base\Model;
11
use yii\base\NotSupportedException;
12
13
use vxm\mfa\IdentityInterface;
14
15
class Identity extends Model implements IdentityInterface
16
{
17
18
    private static $ids = [
19
        'user1',
20
        'user2',
21
        'user3',
22
    ];
23
24
    private $_id;
25
26
    public static function findIdentity($id)
27
    {
28
        if (in_array($id, static::$ids)) {
0 ignored issues
show
Bug introduced by
Since $ids is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $ids to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
29
            $identitiy = new static();
30
            $identitiy->_id = $id;
31
            return $identitiy;
32
        }
33
    }
34
35
    public static function findIdentityByAccessToken($token, $type = null)
36
    {
37
        throw new NotSupportedException();
38
    }
39
40
    public function getId()
41
    {
42
        return $this->_id;
43
    }
44
45
    public function getAuthKey()
46
    {
47
        return 'ABCD1234';
48
    }
49
50
    public function validateAuthKey($authKey)
51
    {
52
        return $authKey === 'ABCD1234';
53
    }
54
55
    public function getMfaSecretKey()
56
    {
57
        return 'ABC';
58
    }
59
60
}
61