Completed
Push — doctrine-tests ( 7f65d5 )
by
unknown
04:56
created

ApplicationLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 3
Metric Value
wmc 3
c 3
b 0
f 3
lcom 0
cbo 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveByApiKeyAndSecret() 0 7 1
A retrieveByApiKeyAndSecretQueryBuilder() 0 10 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
     * Construct.
20
     *
21
     * @param ApplicationRepository $applicationRepository
22
     */
23
    public function __construct(ApplicationRepository $applicationRepository)
24
    {
25
        $this->applicationRepository = $applicationRepository;
26
    }
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
    /**
40
     * @param $apiKey
41
     * @param $secret
42
     * @return \Doctrine\ORM\QueryBuilder
43
     */
44
    public function retrieveByApiKeyAndSecretQueryBuilder($apiKey, $secret)
45
    {
46
        return $this->applicationRepository
47
            ->createQueryBuilder('a')
48
                ->where('a.secret = :secret')
49
                    ->setParameter('secret', $secret)
50
                ->andWhere('a.apiKey = :api_key')
51
                    ->setParameter('api_key', $apiKey)
52
        ;
53
    }
54
}
55