Completed
Pull Request — master (#30)
by nonanerz
04:38
created

UserRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 43.48%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 44
ccs 10
cts 23
cp 0.4348
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadUserByUsername() 0 8 1
A selectUsersByParams() 0 18 2
A selectNotBlocked() 0 8 1
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use Doctrine\ORM\Query;
6
use AppBundle\Entity\DTO\Filter;
7
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
8
9
/**
10
 * UserRepository.
11
 *
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15
class UserRepository extends \Doctrine\ORM\EntityRepository implements UserLoaderInterface
16
{
17 4
    public function loadUserByUsername($username)
18
    {
19 4
        return $this->createQueryBuilder('user')
20 4
            ->andWhere('user.apiToken = :username')
21 4
            ->setParameter('username', $username)
22 4
            ->getQuery()
23 4
            ->getOneOrNullResult();
24
    }
25
26
    /**
27
     * @param Filter $filter
28
     *
29
     * @return Query
30
     */
31 3
    public function selectUsersByParams(Filter $filter):Query
32
    {
33 3
        $postsQuery = $this->createQueryBuilder('u');
34 3
        if ($filter->name) {
35
            $postsQuery->where(
36
                $postsQuery->expr()->like('u.firstName', ':name')
37
            )
38
                ->orWhere(
39
                    $postsQuery->expr()->like('u.lastName', ':name')
40
                )
41
                ->orWhere(
42
                    $postsQuery->expr()->like('u.email', ':name')
43
                )
44
                ->setParameter('name', '%'.$filter->name.'%');
45
        }
46
47 3
        return $postsQuery->getQuery();
48
    }
49
50
    public function selectNotBlocked()
51
    {
52
        return $this->createQueryBuilder('u')
53
            ->andWhere('u.enabled = TRUE')
54
            ->orderBy('u.lastName')
55
            ->getQuery()
56
            ->getResult();
57
    }
58
}
59