Failed Conditions
Pull Request — master (#142)
by Zac
04:15
created

TestResultRepository::getResultsOlderThan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Overwatch\ResultBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * TestResultRepository
9
 * Some shortcut and convienience methods to find test results
10
 */
11
class TestResultRepository extends EntityRepository
12
{
13
    public function getResults($criteria, $pageSize = 10, $page = 1)
14
    {
15
        return $this->findBy(
16
            $criteria,
17
            [
18
                'createdAt' => 'desc'
19
            ],
20
            $pageSize,
21
            ($page - 1) * $pageSize
22
        );
23
    }
24
25
    public function getResultsOlderThan(\DateTime $date)
26
    {
27
        $qb = $this->createQueryBuilder('r');
28
        $qb
29
            ->where(
30
                $qb->expr()->lt(
31
                    'r.createdAt',
32
                    ':timestamp'
33
                )
34
            )
35
            ->setParameter('timestamp', $date)
36
        ;
37
38
        return $qb->getQuery()->iterate();
39
    }
40
}
41