Completed
Push — master ( 5b7ff5...aa63f9 )
by Stepan
16:48 queued 07:41
created

TicketCostService::getEventFreeTicketCount()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Application\Bundle\DefaultBundle\Service;
4
5
use Application\Bundle\DefaultBundle\Entity\TicketCost;
6
use Doctrine\ORM\EntityManager;
7
use Stfalcon\Bundle\EventBundle\Entity\Event;
8
9
/**
10
 * Class TicketCostService.
11
 */
12
class TicketCostService
13
{
14
    /**
15
     * @var EntityManager
16
     */
17
    private $em;
18
19
    /**
20
     * TicketCostService constructor.
21
     *
22
     * @param EntityManager $em
23
     */
24
    public function __construct($em)
25
    {
26
        $this->em = $em;
27
    }
28
29
    /**
30
     * @param Event $event
31
     *
32
     * @return TicketCost
33
     */
34
    public function getCurrentEventTicketCost($event)
35
    {
36
        $eventCosts = $this->em->getRepository('ApplicationDefaultBundle:TicketCost')
37
            ->getEventEnabledTicketsCost($event);
38
39
        $currentTicketCost = null;
40
41
        /** @var TicketCost $cost */
42
        foreach ($eventCosts as $cost) {
43
            if ($cost->isHaveTemporaryCount()) {
44
                $currentTicketCost = $cost;
45
                break;
46
            }
47
        }
48
49
        return $currentTicketCost;
50
    }
51
}
52