Conditions | 4 |
Paths | 2 |
Total Lines | 19 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
29 | public function selectUsersByParams(ParameterBag $params):array |
||
30 | { |
||
31 | $postsQuery = $this->createQueryBuilder('Users') |
||
32 | ->select('u') |
||
33 | ->from('AppBundle:User', 'u') |
||
34 | ->orderBy('u.createdAt', preg_match('/asc/i', $params->get('order')) ? 'ASC' : 'DESC'); |
||
35 | |||
36 | if ($params->has('name') && $params->get('name')) { |
||
37 | $postsQuery->where( |
||
38 | $postsQuery->expr()->like('u.firstName', ':name') |
||
39 | ) |
||
40 | ->orWhere( |
||
41 | $postsQuery->expr()->like('u.lastName', ':name') |
||
42 | ) |
||
43 | ->setParameter('name', '%' . $params->get('name') . '%'); |
||
44 | } |
||
45 | |||
46 | return $postsQuery->getQuery()->getResult(); |
||
47 | } |
||
48 | } |
||
49 |