getLastByAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 11
c 2
b 1
f 0
nc 2
nop 1
dl 0
loc 14
ccs 0
cts 11
cp 0
crap 6
rs 9.9
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