Completed
Pull Request — master (#11)
by Clément
04:00 queued 33s
created

EventRepository::findFirstTodoEvent()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.4285
cc 3
eloc 9
nc 4
nop 3
crap 12
1
<?php
2
3
namespace Itkg\DelayEventBundle\Repository;
4
5
use Doctrine\ODM\MongoDB\DocumentRepository;
6
use Itkg\DelayEventBundle\Model\Event;
7
8
/**
9
 * Class EventRepository
10
 */
11
class EventRepository extends DocumentRepository
12
{
13
    /**
14
     * @param bool  $failed
15
     * @param array $eventTypeIncluded
16
     * @param array $eventTypeExcluded
17
     *
18
     * @return Event
19
     */
20
    public function findFirstTodoEvent($failed = false, array $eventTypeIncluded = [], array $eventTypeExcluded = [])
21
    {
22
        $qb = $this->createQueryBuilder();
23
        $qb->field('failed')->equals($failed);
24
25
        if (!empty($eventTypeIncluded)) {
26
            $qb->field('originalName')->in($eventTypeIncluded);
27
        }
28
29
        if (!empty($eventTypeExcluded)) {
30
            $qb->field('originalName')->notIn($eventTypeExcluded);
31
        }
32
33
        $qb->sort('createdAt', 'asc');
34
35
        return $qb->getQuery()->getSingleResult();
36
    }
37
}
38