AccessTokenRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0
ccs 0
cts 12
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getNewToken() 0 4 1
A persistNewAccessToken() 0 8 2
A revokeAccessToken() 0 4 1
A isAccessTokenRevoked() 0 4 1
1
<?php
2
3
namespace CodexShaper\OAuth2\Server\Repositories;
4
5
use CodexShaper\OAuth2\Server\Entities\AccessToken as AccessTokenEntity;
6
use CodexShaper\OAuth2\Server\Model;
7
use Exception;
8
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
9
use League\OAuth2\Server\Entities\ClientEntityInterface;
10
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
11
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
12
13
class AccessTokenRepository implements AccessTokenRepositoryInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
19
    {
20
        return new AccessTokenEntity($userIdentifier, $scopes, $clientEntity);
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
27
    {
28
        try {
29
            Model::storeAccessToken($accessTokenEntity);
30
        } catch (UniqueTokenIdentifierConstraintViolationException $ex) {
31
            throw new Exception($ex->getMessage());
32
        }
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function revokeAccessToken($tokenId)
39
    {
40
        Model::revoke('tokenModel', $tokenId);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function isAccessTokenRevoked($tokenId)
47
    {
48
        return Model::isRevoked('tokenModel', $tokenId);
49
    }
50
}
51