Completed
Pull Request — dev (#36)
by nonanerz
03:50
created

UserRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 43.48%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A selectUsersByParams() 0 18 2
A loadUserByUsername() 0 8 1
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 1
    public function loadUserByUsername($username)
18
    {
19 1
        return $this->createQueryBuilder('user')
20 1
            ->andWhere('user.apiToken = :username')
21 1
            ->setParameter('username', $username)
22 1
            ->getQuery()
23 1
            ->getOneOrNullResult();
24
    }
25
26
    /**
27
     * @param Filter $filter
28
     * @return Query
29
     */
30 3
    public function selectUsersByParams(Filter $filter):Query
31
    {
32 3
        $postsQuery = $this->createQueryBuilder('u');
33 3
        if ($filter->name) {
34
            $postsQuery->where(
35
                $postsQuery->expr()->like('u.firstName', ':name')
36
            )
37
                ->orWhere(
38
                    $postsQuery->expr()->like('u.lastName', ':name')
39
                )
40
                ->orWhere(
41
                    $postsQuery->expr()->like('u.email', ':name')
42
                )
43
                ->setParameter('name', '%' . $filter->name . '%');
44
        }
45
46 3
        return $postsQuery->getQuery();
47
    }
48
49
    public function selectNotBlocked()
50
    {
51
        return $this->createQueryBuilder('u')
52
            ->andWhere('u.enabled = TRUE')
53
            ->orderBy('u.lastName')
54
            ->getQuery()
55
            ->getResult();
56
    }
57
}
58