DoctrineEventRepository::getCapacity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
/**
4
 * @author    Markus Tacker <[email protected]>
5
 * @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/
6
 */
7
8
namespace BCRM\BackendBundle\Entity\Event;
9
10
use Doctrine\ORM\EntityRepository;
11
use PhpOption\None;
12
use PhpOption\Option;
13
use PhpOption\Some;
14
15
class DoctrineEventRepository extends EntityRepository implements EventRepository
16
{
17
    /**
18
     * @return Option
19
     */
20 View Code Duplication
    public function getNextEvent()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $qb = $this->createQueryBuilder('e');
23
        $qb->andWhere('e.registrationStart <= :now');
24
        $qb->setParameter('now', new \DateTime());
25
        $qb->setMaxResults(1);
26
        $qb->orderBy('e.start', 'ASC');
27
        $event = $qb->getQuery()->getOneOrNullResult();
28
        return $event == null ? None::create() : new Some($event);
29
    }
30
31
    /**
32
     * @param Event $event
33
     * @param       $day
34
     *
35
     * @return integer
36
     */
37
    public function getCapacity(Event $event, $day)
38
    {
39
        return $this->createQueryBuilder('e')
40
            ->select('e.capacity - COUNT(t.id) as capacity')
41
            ->leftJoin('e.tickets', 't')
42
            ->andWhere('t.day = :day')->setParameter('day', $day)
43
            ->andWhere('t.type = :type')->setParameter('type', Registration::TYPE_NORMAL)
44
            ->andWhere('e.id = :event')->setParameter('event', $event->getId())
45
            ->getQuery()
46
            ->getSingleScalarResult();
47
    }
48
49
50
}
51