Completed
Pull Request — master (#30)
by
unknown
03:43
created

UserRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 58.81%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 34
ccs 10
cts 17
cp 0.5881
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A selectUsersByParams() 0 18 2
A loadUserByUsername() 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