Passed
Push — master ( 36be2d...32b990 )
by Carlos
02:58
created

RevokeAccessTokenTrait::revokeActiveAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roaresearch\yii2\oauth2server;
4
5
use roaresearch\yii2\oauth2server\models\OauthAccessTokens as AccessToken;
6
use yii\db\ActiveQuery;
7
8
trait RevokeAccessTokenTrait
9
{
10
    /**
11
     * @inheritdoc
12
     */
13 5
    public static function findIdentityByAccessToken(
14
        $token,
15
        $type = null
16
    ): ?static {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STATIC on line 16 at column 8
Loading history...
17 5
        return static::find()->innerJoinWith([
18 5
            'activeAccessToken' => function (ActiveQuery $query) use ($token) {
19 5
                $query->andWhere(['access_token' => $token]);
20
            },
21 5
        ])->one();
22
    }
23
24
    /**
25
     * @return ActiveQuery
26
     */
27 5
    public function getAccessTokens(): ActiveQuery
28
    {
29 5
        return $this->hasMany(AccessToken::class, ['user_id' => 'id']);
30
    }
31
32
    /**
33
     * @return ActiveQuery
34
     */
35 5
    public function getActiveAccessToken(): ActiveQuery
36
    {
37 5
        $query = $this->getAccessTokens();
38 5
        $query->multiple = false;
39
40 5
        return $query;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 1
    public function getAccessTokenData(): AccessToken
47
    {
48 1
        return $this->activeAccessToken;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 1
    public function revokeActiveAccessToken(): bool
55
    {
56 1
        return $this->getAccessTokenData()->delete();
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function revokeAllAccessTokens(): bool
63
    {
64
        return AccessToken::deleteAll(['user_id' => $this->id]) > 0;
65
    }
66
67
}
68