Completed
Pull Request — master (#142)
by Ihor
15:10
created

Ticket   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B generateSet() 0 27 2
A getById() 0 10 2
1
<?php
2
3
namespace AppBundle\Domain\Ticket;
4
5
use AppBundle\Domain\Seat\SeatInterface;
6
use AppBundle\Entity\PerformanceEvent;
7
use AppBundle\Entity\Seat as SeatEntity;
8
use AppBundle\Entity\Ticket as TicketEntity;
9
use AppBundle\Exception\NotFoundException;
10
use AppBundle\Repository\PerformanceEventRepository;
11
use AppBundle\Repository\TicketRepository;
12
13
class Ticket implements TicketInterface
14
{
15
    /** @var PerformanceEventRepository */
16
    private $ticketRepository;
17
18
    /** @var SeatInterface */
19
    private $seatService;
20
21
    /**
22
     * Domain Ticket constructor.
23
     *
24
     * @param TicketRepository $ticketRepository
25
     * @param SeatInterface $seatService
26
     */
27
    public function __construct(
28
        TicketRepository $ticketRepository,
29
        SeatInterface $seatService
30
    ) {
31
        $this->ticketRepository = $ticketRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ticketRepository of type object<AppBundle\Repository\TicketRepository> is incompatible with the declared type object<AppBundle\Reposit...ormanceEventRepository> of property $ticketRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        $this->seatService = $seatService;
33
    }
34
35
    /**
36
     * @inheritdoc
37
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
38
     */
39
    public function generateSet(PerformanceEvent $performanceEvent, bool $force = false)
40
    {
41
        $seats = $this->seatService->getByVenue($performanceEvent->getVenue());
42
43
        // TODO
44
        // generate only if SET was not generated before
45
        // check PriceCategory, and take price from it;
46
        // get seriesNumber, seriesDate from PerformanceEvent.
47
        // FORCE ticket SET generation
48
        // Log for generated ticket
49
50
        $seriesNumber = 'testTicket';
51
        $seriesDate = new \DateTime('now');
52
        $price = 50;
53
        $count = 0;
54
55
        $tickets = [];
56
        /** @var SeatEntity $seat */
57
        foreach ($seats as $seat) {
58
            $tickets[] = new TicketEntity($seat, $performanceEvent, $price, $seriesDate, $seriesNumber);
59
            $count += 1;
60
        }
61
62
        $this->ticketRepository->batchSave($tickets);
0 ignored issues
show
Documentation Bug introduced by
The method batchSave does not exist on object<AppBundle\Reposit...ormanceEventRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
63
64
        return 'successfully generated '.$count;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function getById(string $id): TicketEntity
71
    {
72
        /** @var TicketEntity $ticket */
73
        $ticket = $this->ticketRepository->find($id);
74
        if (!$ticket) {
75
            throw new NotFoundException('Ticket not found by ID: '.$id);
76
        }
77
78
        return $ticket;
79
    }
80
}
81