Completed
Pull Request — master (#164)
by Ihor
25:00 queued 13:13
created

TicketsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 16.66%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 45
ccs 2
cts 12
cp 0.1666
rs 10
wmc 3
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 4 1
A freeAction() 0 6 1
A reserveAction() 0 6 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\Ticket;
6
use FOS\RestBundle\Controller\Annotations\Get;
7
use FOS\RestBundle\Controller\Annotations\Patch;
8
use FOS\RestBundle\Controller\Annotations\View as RestView;
9
use FOS\RestBundle\Controller\Annotations\RouteResource;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
11
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
12
13
/**
14
 * @RouteResource("Ticket")
15
 */
16
class TicketsController extends Controller
17
{
18
    /**
19
     * @Get(
20
     *     "/tickets/{id}",
21
     *     requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}
22
     *     )
23
     * @ParamConverter("ticket", class="AppBundle:Ticket")
24
     * @RestView(serializerGroups={"get_ticket"})
25
     */
26 2
    public function getAction(Ticket $ticket)
27
    {
28 2
        return $ticket;
29
    }
30
31
    /**
32
     * @RestView(statusCode=204)
33
     * @Patch(
34
     *     "/tickets/{id}/free",
35
     *     requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}
36
     *     )
37
     * @ParamConverter("ticket", class="AppBundle:Ticket")
38
     */
39
    public function freeAction(Ticket $ticket)
40
    {
41
        $em = $this->getDoctrine()->getManager();
42
        $ticket->setStatus(Ticket::STATUS_FREE);
43
        $em->flush();
44
    }
45
46
    /**
47
     * @RestView(statusCode=204)
48
     * @Patch(
49
     *     "/tickets/{id}/reserve",
50
     *     requirements={"id" = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"}
51
     *     )
52
     * @ParamConverter("ticket", class="AppBundle:Ticket")
53
     */
54
    public function reserveAction(Ticket $ticket)
55
    {
56
        $em = $this->getDoctrine()->getManager();
57
        $ticket->setStatus(Ticket::STATUS_BOOKED);
58
        $em->flush();
59
    }
60
}
61