EventRepository::selectNotExpiredByUser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 15
ccs 0
cts 13
cp 0
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
crap 6
1
<?php
2
3
namespace AppBundle\Repository;
4
5
/**
6
 * EventRepository.
7
 *
8
 * This class was generated by the Doctrine ORM. Add your own custom
9
 * repository methods below.
10
 */
11
class EventRepository extends \Doctrine\ORM\EntityRepository
12
{
13
    public function findByGoogleId($id)
14
    {
15
        return $this->createQueryBuilder('e')
16
            ->andWhere('e.googleId = :id')
17
            ->setParameter('id', $id)
18
            ->getQuery()
19
            ->getSingleResult();
20
    }
21
22
    public function selectNotExpiredByUser($user, $dashboard = false)
23
    {
24
        $qb = $this->createQueryBuilder('e')
25
            ->join('e.user', 'user')
26
            ->andWhere('user = :user')
27
            ->setParameter('user', $user)
28
            ->andWhere('e.expiredAt >= :date')
29
            ->setParameter('date', new \DateTime());
30
31
        if ($dashboard) {
32
            $qb->setMaxResults(2);
33
        }
34
35
        return $qb->getQuery()->getResult();
36
    }
37
}
38