Completed
Push — master ( 87eb9e...2b0bcc )
by Serhii
11s
created

findByDateRangeAndSlug()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 16
nc 4
nop 4
dl 0
loc 25
ccs 3
cts 4
cp 0.75
crap 3.1406
rs 8.8571
c 1
b 1
f 0
1
<?php
2
3
namespace AppBundle\Repository;
4
5
class PerformanceEventRepository extends AbstractRepository
6
{
7 2
    /**
8
     * @param \DateTime $fromDate
9 2
     * @param \DateTime $toDate
10 2
     * @param string $limit
11 2
     * @param null $performanceSlug
12 2
     * @return mixed
13 2
     */
14
    public function findByDateRangeAndSlug(
15
        \DateTime $fromDate,
16 2
        \DateTime $toDate,
17
        $limit = 'all',
18
        $performanceSlug = null
19
    ) {
20 2
        $qb = $this->createQueryBuilder('u')
21
            ->WHERE('u.dateTime BETWEEN :from AND :to')
22 2
            ->setParameter('from', $fromDate->format('Y-m-d H:i'))
23
            ->setParameter('to', $toDate->format('Y-m-d H:i'))
24
            ->orderBy('u.dateTime', 'ASC')
25
        ;
26
27
        if ('all' !== $limit) {
28
            $qb->setMaxResults($limit);
29
        }
30
31
        if ($performanceSlug) {
32
            $qb->join('u.performance', 'p')->andWhere('p.slug = :slug')->setParameter('slug', $performanceSlug);
33
        }
34
35
        $query = $qb->getQuery();
36
37
        return $query->execute();
38
    }
39
}
40