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

TicketsController::reserveAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
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