Passed
Push — master ( fb60c6...a721e7 )
by Rutger
03:14
created

revokeRefreshTokensByAccessTokenIds()   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 24
ccs 0
cts 14
cp 0
rs 9.7998
cc 3
nc 8
nop 1
crap 12
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\components\repositories;
4
5
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
6
use rhertogh\Yii2Oauth2Server\components\repositories\base\Oauth2BaseTokenRepository;
7
use rhertogh\Yii2Oauth2Server\components\repositories\traits\Oauth2ModelRepositoryTrait;
8
use rhertogh\Yii2Oauth2Server\helpers\DiHelper;
9
use rhertogh\Yii2Oauth2Server\interfaces\components\repositories\Oauth2RefreshTokenRepositoryInterface;
10
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2AccessTokenInterface;
11
use rhertogh\Yii2Oauth2Server\interfaces\models\Oauth2RefreshTokenInterface;
12
13
class Oauth2RefreshTokenRepository extends Oauth2BaseTokenRepository implements Oauth2RefreshTokenRepositoryInterface
14
{
15
    use Oauth2ModelRepositoryTrait;
16
17
    /**
18
     * @inheritDoc
19
     * @return class-string<Oauth2RefreshTokenInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Oauth2RefreshTokenInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Oauth2RefreshTokenInterface>.
Loading history...
20
     */
21 5
    public function getModelClass()
22
    {
23 5
        return Oauth2RefreshTokenInterface::class;
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29 3
    public function getNewRefreshToken()
30
    {
31 3
        return static::getNewTokenInternally();
0 ignored issues
show
Bug Best Practice introduced by
The method rhertogh\Yii2Oauth2Serve...getNewTokenInternally() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        return static::/** @scrutinizer ignore-call */ getNewTokenInternally();
Loading history...
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37 2
    public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
38
    {
39 2
        static::persistToken($refreshTokenEntity);
0 ignored issues
show
Bug Best Practice introduced by
The method rhertogh\Yii2Oauth2Serve...ository::persistToken() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        static::/** @scrutinizer ignore-call */ 
40
                persistToken($refreshTokenEntity);
Loading history...
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 1
    public function revokeRefreshToken($tokenId)
46
    {
47 1
        static::revokeToken($tokenId);
0 ignored issues
show
Bug Best Practice introduced by
The method rhertogh\Yii2Oauth2Serve...pository::revokeToken() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        static::/** @scrutinizer ignore-call */ 
48
                revokeToken($tokenId);
Loading history...
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53 1
    public function isRefreshTokenRevoked($tokenId)
54
    {
55 1
        return static::isTokenRevoked($tokenId);
0 ignored issues
show
Bug Best Practice introduced by
The method rhertogh\Yii2Oauth2Serve...itory::isTokenRevoked() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        return static::/** @scrutinizer ignore-call */ isTokenRevoked($tokenId);
Loading history...
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function revokeRefreshTokensByAccessTokenIds($accessTokenIds)
62
    {
63
        $class = $this->getModelClass();
64
        /** @var class-string<Oauth2RefreshTokenInterface> $className */
65
        $className = DiHelper::getValidatedClassName($class);
66
67
        $db = $className::getDb();
68
69
        $transaction = $db->beginTransaction();
70
71
        try {
72
            /** @var Oauth2RefreshTokenInterface[] $refreshTokens */
73
            $refreshTokens = $className::findAllByAccessTokenIds($accessTokenIds);
74
            foreach ($refreshTokens as $refreshToken) {
75
                $refreshToken->setRevokedStatus(true);
76
                $refreshToken->persist();
77
            }
78
            $transaction->commit();
79
        } catch (\Exception $e) {
80
            $transaction->rollBack();
81
            throw $e;
82
        }
83
84
        return $refreshTokens;
85
    }
86
}
87