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

AccountLoader::__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\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