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

TokenLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 45
ccs 0
cts 10
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveByHash() 0 10 1
A retrieveExpired() 0 10 1
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