Completed
Push — master ( 5ac7c0...d84236 )
by
16:21
created

UserRepository::loadUserByAuthorizationRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
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();
0 ignored issues
show
Documentation Bug introduced by
The method getQueryBuilder does not exist on object<DoS\UserBundle\Do...ine\ORM\UserRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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
    public function loadUserByAuthorizationRoles(array $roles)
46
    {
47
        $queryBuilder = $this->createQueryBuilder('o');
48
        $queryBuilder
49
            ->join('o.authorizationRoles', 'a')
50
            ->andWhere($queryBuilder->expr()->in('a.code', ':roles'))
51
            ->setParameter('roles', $roles)
52
        ;
53
54
        return $queryBuilder->getQuery()->getResult();
55
    }
56
}
57