Passed
Push — master ( 25c2e9...26c6a8 )
by Petr
08:32
created

OrganizerController::createAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Controller\Infrastructure\RestController;
6
use AppBundle\Entity\Organizer;
7
use AppBundle\Form\Ambassador\OrganizerFormType;
8
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
/**
16
 * @author Vehsamrak
17
 * @Route("organizer")
18
 */
19
class OrganizerController extends RestController
20
{
21
22
    /**
23
     * List all registered organizers
24
     * @Route("s/{limit}/{offset}", name="organizers_list")
25
     * @Method("GET")
26
     * @ApiDoc(
27
     *     section="Organizer",
28
     *     requirements={
29
     *         {
30
     *             "name"="limit",
31
     *             "dataType"="int",
32
     *             "requirement"="false",
33
     *             "description"="limit number. Default is 50"
34
     *         },
35
     *         {
36
     *             "name"="offset",
37
     *             "dataType"="int",
38
     *             "requirement"="false",
39
     *             "description"="offset number. Default is 0"
40
     *         },
41
     *     },
42
     *     statusCodes={
43
     *         200="OK",
44
     *     }
45
     * )
46
     * @param int $limit Limit results. Default is 50
47
     * @param int $offset Starting serial number of result collection. Default is 0
48
     */
49 1
    public function listAction($limit = null, $offset = null): Response
50
    {
51 1
        return $this->listEntities($this->get('rockparade.organizer_repository'), $limit, $offset);
52
    }
53
54
    /**
55
     * View organizer by name
56
     * @Route("/{id}", name="organizer_view")
57
     * @Method("GET")
58
     * @ApiDoc(
59
     *     section="Organizer",
60
     *     requirements={
61
     *         {
62
     *             "name"="id",
63
     *             "dataType"="string",
64
     *             "requirement"="true",
65
     *             "description"="organizer name"
66
     *         },
67
     *     },
68
     *     statusCodes={
69
     *         200="Organizer was found",
70
     *         404="Organizer with given name was not found",
71
     *     }
72
     * )
73
     * @param string $id organizer name
74
     */
75 3
    public function viewAction(string $id): Response
76
    {
77 3
        return $this->viewEntity($this->get('rockparade.organizer_repository'), $id);
78
    }
79
80
    /**
81
     * Create new band
82
     * @Route("", name="organizer_create")
83
     * @Method("POST")
84
     * @Security("has_role('ROLE_USER')")
85
     * @ApiDoc(
86
     *     section="Organizer",
87
     *     requirements={
88
     *         {
89
     *             "name"="name",
90
     *             "dataType"="string",
91
     *             "requirement"="true",
92
     *             "description"="organization name"
93
     *         },
94
     *         {
95
     *             "name"="description",
96
     *             "dataType"="string",
97
     *             "requirement"="true",
98
     *             "description"="organization description"
99
     *         },
100
     *         {
101
     *             "name"="members",
102
     *             "dataType"="array",
103
     *             "requirement"="false",
104
     *             "description"="logins and short descriptions of organization members"
105
     *         },
106
     *     },
107
     *     statusCodes={
108
     *         201="New organizer was created. Link to new resource provided in header 'Location'",
109
     *         400="Validation error",
110
     *     }
111
     * )
112
     */
113 2 View Code Duplication
    public function createAction(Request $request): Response
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...
114
    {
115 2
        $form = $this->createAndProcessForm($request, OrganizerFormType::class);
116
117 2
        $apiResponseFactory = $this->get('rockparade.api_response_factory');
118 2
        $response = $apiResponseFactory->createResponse(
119 2
            $this->createApiOperation($request),
120
            $form,
121 2
            $this->getUser(),
122 2
            Organizer::class
123
        );
124
125 2
        return $this->respond($response);
126
    }
127
}
128