AuthenticatorQueryObject   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createQuery() 0 15 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