SentEmailRepository::search()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 3
Bugs 3 Features 0
Metric Value
cc 4
eloc 15
c 3
b 3
f 0
nc 2
nop 1
dl 0
loc 26
ccs 0
cts 11
cp 0
crap 20
rs 9.7666
1
<?php
2
3
namespace Azine\EmailBundle\Entity\Repositories;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\Query;
7
8
/**
9
 * SentEmailRepository.
10
 *
11
 * This class was generated by the Doctrine ORM. Add your own custom
12
 * repository methods below.
13
 */
14
class SentEmailRepository extends EntityRepository
15
{
16
    /**
17
     * Search SentEmails by search params.
18
     *
19
     * @param $searchParams
20
     *
21
     * @return Query
22
     */
23
    public function search($searchParams = array())
24
    {
25
        $queryBuilder = $this->createQueryBuilder('e');
26
27
        if (!empty($searchParams)) {
28
            $searchAttributes = array(
29
                'recipients',
30
                'template',
31
                'sent',
32
                'variables',
33
                'token',
34
            );
35
36
            foreach ($searchAttributes as $attribute) {
37
                if (empty($searchParams[$attribute])) {
38
                    continue;
39
                }
40
41
                $attributeValue = $searchParams[$attribute];
42
43
                $queryBuilder->andWhere('e.'.$attribute.' LIKE :'.$attribute)
44
                    ->setParameter($attribute, '%'.$attributeValue.'%');
45
            }
46
        }
47
48
        return $queryBuilder->getQuery();
49
    }
50
}
51