AuthenticatorQueryObject::createQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\Authentication\Query;
6
7
use Doctrine\ORM\QueryBuilder;
8
use SixtyEightPublishers\User\Common\UserMapping;
9
use SixtyEightPublishers\DoctrineQueryObjects\AbstractQueryObject;
10
use SixtyEightPublishers\User\Authentication\Entity\UserInterface;
11
use SixtyEightPublishers\DoctrineQueryObjects\QueryFactory\QueryFactoryInterface;
12
13
final class AuthenticatorQueryObject extends AbstractQueryObject
14
{
15
	/** @var string  */
16
	private $username;
17
18
	/** @var \SixtyEightPublishers\User\Common\UserMapping  */
19
	private $userMapping;
20
21
	/**
22
	 * @param string                                        $username
23
	 * @param \SixtyEightPublishers\User\Common\UserMapping $userMapping
24
	 */
25
	public function __construct(string $username, UserMapping $userMapping)
26
	{
27
		$this->username = $username;
28
		$this->userMapping = $userMapping;
29
	}
30
31
	/**
32
	 * {@inheritDoc}
33
	 */
34
	public function createQuery(QueryFactoryInterface $queryFactory): QueryBuilder
35
	{
36
		$builder = $queryFactory->createQueryBuilder();
37
38
		$condition = $builder->expr()->eq(
39
			'u.' . $this->userMapping[$this->userMapping::FIELD_USERNAME],
40
			':username'
41
		);
42
43
		return $builder
44
			->select('u')
45
			->from(UserInterface::class, 'u')
46
			->where($condition)
47
			->setParameter('username', $this->username);
48
	}
49
}
50