UserIdentity::validateAuthKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace hiapi\Core\Auth;
4
5
use yii\base\Model;
6
use yii\web\IdentityInterface;
7
8
/**
9
 * Basic user identity.
10
 * We'll see if it is enough.
11
 */
12
class UserIdentity extends Model implements IdentityInterface
13
{
14
    public $id;
15
    public $username;
16
    public $state;
17
    public $roles = [];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 View Code Duplication
    public function rules()
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...
23
    {
24
        return [
25
            ['id',          'integer'],
26
            ['username',    'string'],
27
            ['state',       'string'],
28
            ['roles',       'trim'],
29
        ];
30
    }
31
32
    /** {@inheritdoc} */
33
    public static function findIdentity($id)
34
    {
35
        throw new \yii\base\InvalidCallException('no `findIdentity` and not expected');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public static function findIdentityByAccessToken($token, $type = null)
42
    {
43
        throw new \yii\base\InvalidCallException('no `findIdentityByAccessToken` and not expected');
44
    }
45
46
    public static function fromArray(array $info): self
47
    {
48
        $id = $info['id'] ?? $info['sub'] ?? null;
49
50
        if (empty($id)) {
51
            return null;
52
        }
53
54
        return new static([
55
            'id'        => $id,
56
            'username'  => $info['username'] ?? $info['email'] ?? null,
57
            'state'     => $info['state'] ?? null,
58
            'roles'     => $info['roles'] ?? null,
59
        ]);
60
    }
61
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getId()
67
    {
68
        return $this->id;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getAuthKey()
75
    {
76
        return null;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function validateAuthKey($authKey)
83
    {
84
        return false;
85
    }
86
}
87