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

AccountLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 44
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A retrieveOnApplicationByUsername() 0 6 1
A retrieveOnApplicationByUsernameQueryBuilder() 0 10 1
1
<?php
2
3
namespace Majora\Component\OAuth\Loader\ORM;
4
5
use Majora\Component\OAuth\Loader\AccountLoaderInterface;
6
use Majora\Component\OAuth\Model\ApplicationInterface;
7
use Majora\Component\OAuth\Repository\ORM\AccountRepository;
8
9
/**
10
 * ORM Account loading implementation.
11
 */
12
class AccountLoader implements AccountLoaderInterface
13
{
14
    /**
15
     * @var AccountRepository
16
     */
17
    protected $accountRepository;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param AccountRepository $accountRepository
23
     */
24 4
    public function __construct(AccountRepository $accountRepository)
25
    {
26 4
        $this->accountRepository = $accountRepository;
27 4
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function retrieveOnApplicationByUsername(ApplicationInterface $application, $username)
33
    {
34
        return $this->retrieveOnApplicationByUsernameQueryBuilder($application, $username)
35
            ->getQuery()
36
            ->getOneOrNullResult();
37
    }
38
39
    /**
40
     * @param ApplicationInterface $application
41
     * @param                      $username
42
     *
43
     * @return \Doctrine\ORM\QueryBuilder
44
     */
45 2
    public function retrieveOnApplicationByUsernameQueryBuilder(ApplicationInterface $application, $username)
46
    {
47 2
        return $this->accountRepository
48 2
            ->createQueryBuilder('ac')
49 2
            ->innerJoin('ac.applications', 'app')
50 2
            ->where('ac.username = :username')
51 2
            ->setParameter('username', $username)
52 2
            ->andWhere('app.id = :application')
53 2
            ->setParameter('application', $application->getId());
54
    }
55
}
56