AccountLoader::retrieveOnApplicationByUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
crap 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->accountRepository
35
            ->createQueryBuilder('ac')
36
                ->innerJoin('ac.applications', 'app')
37
                ->where('ac.username = :username')
38
                    ->setParameter('username', $username)
39
                ->andWhere('app.id = :application')
40
                    ->setParameter('application', $application->getId())
41
            ->getQuery()
42
                ->getOneOrNullResult()
43
        ;
44
    }
45
}
46