Completed
Push — master ( 24ab37...36f73c )
by Derek Stephen
01:35
created

RefreshTokenRepository::revokeRefreshToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php
2
3
namespace OAuth\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
7
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
8
use OAuth\RefreshToken;
9
10
/**
11
 * Class RefreshTokenRepository
12
 * @package OAuth\Repository
13
 */
14
class RefreshTokenRepository extends EntityRepository implements RefreshTokenRepositoryInterface
15
{
16
    /**
17
     * @return RefreshToken
18
     */
19
    public function getNewRefreshToken()
20
    {
21
        return new RefreshToken();
22
    }
23
24
    /**
25
     * @param RefreshTokenEntityInterface $refreshTokenEntity
26
     * @return RefreshTokenEntityInterface
27
     * @throws \Doctrine\ORM\OptimisticLockException
28
     */
29
    public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
30
    {
31
        $this->_em->persist($refreshTokenEntity);
32
        $this->_em->flush();
33
34
        return $refreshTokenEntity;
35
    }
36
37
    /**
38
     * @param string $tokenId
39
     * @return bool
40
     * @throws \Doctrine\ORM\ORMException
41
     * @throws \Doctrine\ORM\OptimisticLockException
42
     * @throws \Doctrine\ORM\TransactionRequiredException
43
     */
44
    public function revokeRefreshToken($tokenId)
45
    {
46
        $token = $this->_em->find(RefreshToken::class, $tokenId);
47
        if ($token instanceof RefreshTokenEntityInterface) {
48
            $this->_em->remove($token);
49
            $this->_em->flush();
50
51
            return true;
52
        }
53
54
        return false;
55
    }
56
57
    /**
58
     * @param string $tokenId
59
     * @return bool
60
     * @throws \Doctrine\ORM\ORMException
61
     * @throws \Doctrine\ORM\OptimisticLockException
62
     * @throws \Doctrine\ORM\TransactionRequiredException
63
     */
64
    public function isRefreshTokenRevoked($tokenId)
65
    {
66
        $token = $this->_em->find(RefreshToken::class, $tokenId);
67
        if ($token instanceof RefreshTokenEntityInterface) {
68
69
            return false;
70
        }
71
72
        return true;
73
    }
74
}