Passed
Push — master ( 897bc8...5aa273 )
by Derek Stephen
02:48
created

AccessTokenRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 57.89%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 53
ccs 11
cts 19
cp 0.5789
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A revokeAccessToken() 0 9 2
A getNewToken() 0 5 1
A persistNewAccessToken() 0 5 1
A isAccessTokenRevoked() 0 8 3
1
<?php
2
3
namespace OAuth\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Exception;
7
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
10
use OAuth\AccessToken;
11
12
class AccessTokenRepository extends EntityRepository implements AccessTokenRepositoryInterface
13
{
14
    /**
15
     * @param AccessTokenEntityInterface $accessTokenEntity
16
     * @return AccessTokenEntityInterface
17
     * @throws \Doctrine\ORM\OptimisticLockException
18
     */
19 3
    public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): AccessTokenEntityInterface
20
    {
21 3
        $this->_em->persist($accessTokenEntity);
22 3
        $this->_em->flush();
23 3
        return $accessTokenEntity;
24
    }
25
26
    /**
27
     * @param string $tokenId
28
     * @throws Exception
29
     */
30
    public function revokeAccessToken($tokenId)
31
    {
32
        /** @var AccessToken $token */
33
        $token = $this->find($tokenId);
34
        if(!$token) {
0 ignored issues
show
introduced by
$token is of type OAuth\AccessToken, thus it always evaluated to true.
Loading history...
35
            throw new Exception('Token not found', 404);
36
        }
37
        $token->setRevoked(true);
38
        $this->_em->flush($token);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function isAccessTokenRevoked($tokenId)
45
    {
46
        /** @var null|AccessToken $token */
47 1
        $token = $this->findOneBy(['identifier' => $tokenId]);
48 1
        if(!$token || $token->isRevoked()) {
49
            return true;
50
        }
51 1
        return false;
52
    }
53
54
    /**
55
     * @param ClientEntityInterface $clientEntity
56
     * @param array $scopes
57
     * @param null $userIdentifier
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $userIdentifier is correct as it would always require null to be passed?
Loading history...
58
     * @return AccessTokenEntityInterface|AccessToken
59
     */
60 3
    public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessToken
61
    {
62 3
        $token =  new AccessToken();
63
64 3
        return $token;
65
    }
66
}