EmailTrafficStatisticsRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 12
c 2
b 1
f 0
dl 0
loc 23
ccs 0
cts 11
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getLastByAction() 0 14 2
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\Entity\Repositories;
4
5
use Azine\MailgunWebhooksBundle\Entity\EmailTrafficStatistics;
6
use Doctrine\ORM\EntityRepository;
7
8
/**
9
 * EmailTrafficStatisticsRepository.
10
 *
11
 * This entity is used to store some events that occurred regarding mailgun.
12
 * E.g. when has the last notification about a SPAM complaint been sent to the administrator.
13
 */
14
class EmailTrafficStatisticsRepository extends EntityRepository
15
{
16
    /**
17
     * Get last EmailTrafficStatistics by action.
18
     *
19
     * @param $action
20
     *
21
     * @return EmailTrafficStatistics
22
     */
23
    public function getLastByAction($action)
24
    {
25
        $q = $this->getEntityManager()->createQueryBuilder()
26
            ->setMaxResults(1)
27
            ->select('e')
28
            ->from($this->getEntityName(), 'e')
29
            ->where('e.action = :action')
30
            ->orderBy('e.created ', 'desc')
31
            ->setParameters(array('action' => $action));
32
33
        try {
34
            return $q->getQuery()->getSingleResult();
35
        } catch (\Doctrine\ORM\NoResultException $e) {
36
            return null;
37
        }
38
    }
39
}
40