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

AccessTokenRepository::getNewToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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