AccessTokenRepository::persistNewAccessToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 2
nc 2
nop 1
crap 6
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