Completed
Push — master ( 133170...772a04 )
by Dominik
04:23
created

SentEmailRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0
ccs 0
cts 18
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B search() 0 29 4
1
<?php
2
3
namespace Azine\EmailBundle\Entity\Repositories;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\QueryBuilder;
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
     * @param $searchParams
19
     * @return array of SentEmail
20
     */
21
    public function search($searchParams = [])
22
    {
23
        $queryBuilder = $this->createQueryBuilder('e');
24
25
        if (!empty($searchParams)) {
26
27
            $searchAttributes = [
28
                'recipients',
29
                'template',
30
                'sent',
31
                'variables',
32
                'token'
33
            ];
34
35
            foreach ($searchAttributes as $attribute) {
36
                if (empty($searchParams[$attribute])) {
37
                    continue;
38
                }
39
40
                $attributeValue = $searchParams[$attribute];
41
42
                $queryBuilder->andWhere('e.'.$attribute.' LIKE :'.$attribute)
43
                    ->setParameter($attribute, '%'.$attributeValue.'%');
44
            }
45
        }
46
47
        $sentEmails = $queryBuilder->getQuery()->getResult();
48
        return $sentEmails;
49
    }
50
}
51