Completed
Pull Request — master (#2)
by Vojtěch
10:05
created

GetUserByEmailQueryFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\ForgotPassword\Query;
6
7
use Nette;
8
use Doctrine;
9
use SixtyEightPublishers;
10
11
class GetUserByEmailQueryFactory implements IGetUserByEmailQueryFactory
12
{
13
	use Nette\SmartObject;
14
15
	/** @var \SixtyEightPublishers\User\Common\UserMapping  */
16
	private $mapping;
17
18
	/**
19
	 * @param \SixtyEightPublishers\User\Common\UserMapping $mapping
20
	 */
21
	public function __construct(SixtyEightPublishers\User\Common\UserMapping $mapping)
22
	{
23
		$this->mapping = $mapping;
24
	}
25
26
	/********* interface \SixtyEightPublishers\User\ForgotPassword\Query\IGetUserByEmailQueryFactory *********/
27
28
	/**
29
	 * {@inheritdoc}
30
	 */
31
	public function create(Doctrine\ORM\EntityManagerInterface $em, string $email): Doctrine\ORM\Query
32
	{
33
		return $em->createQueryBuilder()
34
			->select('u')
35
			->from(SixtyEightPublishers\User\ForgotPassword\DoctrineEntity\IUser::class, 'u')
36
			->where('u.' . $this->mapping[SixtyEightPublishers\User\Common\UserMapping::FILED_EMAIL] . ' = :email')
37
			->setParameter('email', $email)
38
			->setMaxResults(1)
39
			->getQuery();
40
	}
41
}
42