EventRepository::findFirstTodoEvent()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 16
cp 0
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 11
nc 8
nop 4
crap 20
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
     * @param string|null $groupFieldIdentifier
18
     * @return Event
19
     */
20
    public function findFirstTodoEvent($failed = false, array $eventTypeIncluded = [], array $eventTypeExcluded = [], $groupFieldIdentifier = null)
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
        if (null !== $groupFieldIdentifier) {
34
            $qb->field('groupFieldIdentifier')->equals($groupFieldIdentifier);
35
        }
36
37
        $qb->sort('createdAt', 'asc');
38
39
        return $qb->getQuery()->getSingleResult();
40
    }
41
42
    /**
43
     * @param array $includedEvents
44
     * @param array $excludedEvents
45
     *
46
     * @return array
47
     */
48
    public function findDistinctFieldGroupIdentifierByChannel(array $includedEvents, array $excludedEvents)
49
    {
50
        $qb = $this->createQueryBuilder();
51
        $qb->distinct('groupFieldIdentifier');
52
        $qb->field('failed')->equals(false);
53
54
        if (!empty($includedEvents)) {
55
            $qb->field('originalName')->in($includedEvents);
56
        }
57
58
        if (!empty($excludedEvents)) {
59
            $qb->field('originalName')->notIn($excludedEvents);
60
        }
61
62
        return $qb->getQuery()->execute();
63
    }
64
}
65