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

ApplicationLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 43
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveByApiKeyAndSecret() 0 6 1
A retrieveByApiKeyAndSecretQueryBuilder() 0 9 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