Completed
Pull Request — master (#26)
by Dominik
02:16 queued 50s
created

getLastByAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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