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

retrieveOnApplicationByUsernameQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
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
     * Construct.
21
     *
22
     * @param AccountRepository $accountRepository
23
     */
24
    public function __construct(AccountRepository $accountRepository)
25
    {
26
        $this->accountRepository = $accountRepository;
27
    }
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
    /**
41
     * @param ApplicationInterface $application
42
     * @param $username
43
     * @return \Doctrine\ORM\QueryBuilder
44
     */
45
    public function retrieveOnApplicationByUsernameQueryBuilder(ApplicationInterface $application, $username)
46
    {
47
        return $this->accountRepository
48
            ->createQueryBuilder('ac')
49
                ->innerJoin('ac.applications', 'app')
50
                ->where('ac.username = :username')
51
                    ->setParameter('username', $username)
52
                ->andWhere('app.id = :application')
53
                    ->setParameter('application', $application->getId())
54
        ;
55
    }
56
}
57