Completed
Push — nyx-refresh-token-orm-config ( 30c2e2...f6baea )
by Quentin
05:18
created

TokenLoader::retrieveExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Majora\Component\OAuth\Loader\ORM;
4
5
use Majora\Component\OAuth\Loader\TokenLoaderInterface;
6
use Majora\Component\OAuth\Repository\ORM\TokenRepository;
7
8
/**
9
 * ORM token loading implementation.
10
 */
11
class TokenLoader implements TokenLoaderInterface
12
{
13
    /**
14
     * @var TokenRepository
15
     */
16
    protected $tokenRepository;
17
18
    /**
19
     * Construct.
20
     *
21
     * @param TokenRepository $tokenRepository
22
     */
23
    public function __construct(TokenRepository $tokenRepository)
24
    {
25
        $this->tokenRepository = $tokenRepository;
26
    }
27
28
    /**
29
     * @see TokenLoaderInterface::retrieveByHash()
30
     */
31
    public function retrieveByHash($hash)
32
    {
33
        return $this->tokenRepository
34
            ->createQueryBuilder('t')
35
                ->where('t.hash = :hash')
36
                ->setParameter('hash', $hash)
37
            ->getQuery()
38
                ->getOneOrNullResult()
39
        ;
40
    }
41
42
    /**
43
     * @see TokenLoaderInterface::retrieveExpired()
44
     */
45
    public function retrieveExpired(\DateTime $datetime)
46
    {
47
        return $this->tokenRepository
48
            ->createQueryBuilder('t')
49
                ->where('t.expireAt > :date')
50
                ->setParameter('date', $datetime)
51
            ->getQuery()
52
                ->getResult()
53
        ;
54
    }
55
}
56