Completed
Push — v2.2 ( 772356...d9dfef )
by Quentin
02:02
created

ApplicationLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Majora\Component\OAuth\Loader\ORM;
4
5
use Majora\Component\OAuth\Loader\ApplicationLoaderInterface;
6
use Majora\Component\OAuth\Repository\ORM\ApplicationRepository;
7
8
/**
9
 * ORM Application loading implementation.
10
 */
11
class ApplicationLoader implements ApplicationLoaderInterface
12
{
13
    /**
14
     * @var ApplicationRepository
15
     */
16
    protected $applicationRepository;
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param ApplicationRepository $applicationRepository
22
     */
23 4
    public function __construct(ApplicationRepository $applicationRepository)
24
    {
25 4
        $this->applicationRepository = $applicationRepository;
26 4
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function retrieveByApiKeyAndSecret($apiKey, $secret)
32
    {
33
        return $this->retrieveByApiKeyAndSecretQueryBuilder($apiKey, $secret)
34
            ->getQuery()
35
            ->getOneOrNullResult();
36
    }
37
38
    /**
39
     * @param $apiKey
40
     * @param $secret
41
     *
42
     * @return \Doctrine\ORM\QueryBuilder
43
     */
44 2
    public function retrieveByApiKeyAndSecretQueryBuilder($apiKey, $secret)
45
    {
46 2
        return $this->applicationRepository
47 2
            ->createQueryBuilder('a')
48 2
            ->where('a.secret = :secret')
49 2
            ->setParameter('secret', $secret)
50 2
            ->andWhere('a.apiKey = :api_key')
51 2
            ->setParameter('api_key', $apiKey);
52
    }
53
}
54