Completed
Push — develop ( 3b6c0f...086e9f )
by Serhii
03:23 queued 57s
created

AbstractRepository::search()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Repository;
4
5
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6
7
abstract class AbstractRepository extends ServiceEntityRepository
8
{
9
    public const CACHE_TTL = 60*60*24;
10
11
    public function getCount()
12
    {
13
        $qb = $this->createQueryBuilder('u');
14
        $query = $qb->select($qb->expr()->count('u'))->getQuery();
15
16
        return $query->getSingleScalarResult();
17
    }
18
19
    public function search(array $fields, string $query): array
20
    {
21
        $qb = $this->createQueryBuilder('e');
22
23
        foreach ($fields as $field) {
24
            $qb->orWhere("e.$field LIKE :query")
25
                ->setParameter('query', "%$query%");
26
        }
27
28
29
        return $qb->getQuery()->getResult();
30
    }
31
}
32