Completed
Push — master ( e9e143...ec9d59 )
by
14:21
created

UserRepository::getCollectionQueryBuilderBetweenDates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
1
<?php
2
3
namespace DoS\UserBundle\Doctrine\ORM;
4
5
use Doctrine\ORM\NonUniqueResultException;
6
use DoS\UserBundle\Confirmation\ConfirmationSubjectFinderInterface;
7
use Sylius\Bundle\UserBundle\Doctrine\ORM\UserRepository as BaseUserRepository;
8
9
/**
10
 * User repository.
11
 */
12
class UserRepository extends BaseUserRepository implements ConfirmationSubjectFinderInterface
13
{
14
    /**
15
     * @param $propertyPath
16
     * @param $value
17
     * @return mixed
18
     * @throws NonUniqueResultException
19
     */
20
    public function findConfirmationSubject($propertyPath, $value)
21
    {
22
        $queryBuilder = $this->getQueryBuilder();
23
        $paths = explode('.', $propertyPath);
24
25
        // support only 1 step join
26
        if (count($paths) > 1) {
27
            $queryBuilder
28
                ->join($this->getPropertyName($paths[0]), '_p1')
29
                ->where('_p1.' . $paths[1] . ' = :value')
30
                ->setParameter('value', $value)
31
            ;
32
        } else {
33
            $queryBuilder
34
                ->where($this->getPropertyName($propertyPath) . ' = :value')
35
                ->setParameter('value', $value)
36
            ;
37
        }
38
39
        return $queryBuilder
40
            ->getQuery()
41
            ->getOneOrNullResult()
42
            ;
43
    }
44
}
45