Passed
Push — master ( eabfa3...2db6fa )
by Petr
04:00
created

OrganizerController::createMemberAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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 AppBundle\Response\ApiValidationError;
9
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
 * @author Vehsamrak
18
 * @Route("organizer")
19
 */
20
class OrganizerController extends RestController
21
{
22
23
    /**
24
     * List all registered organizers
25
     * @Route("s/{limit}/{offset}", name="organizers_list")
26
     * @Method("GET")
27
     * @ApiDoc(
28
     *     section="Organizer",
29
     *     requirements={
30
     *         {
31
     *             "name"="limit",
32
     *             "dataType"="int",
33
     *             "requirement"="false",
34
     *             "description"="limit number. Default is 50"
35
     *         },
36
     *         {
37
     *             "name"="offset",
38
     *             "dataType"="int",
39
     *             "requirement"="false",
40
     *             "description"="offset number. Default is 0"
41
     *         },
42
     *     },
43
     *     statusCodes={
44
     *         200="OK",
45
     *     }
46
     * )
47
     * @param int $limit Limit results. Default is 50
48
     * @param int $offset Starting serial number of result collection. Default is 0
49
     */
50 1
    public function listAction($limit = null, $offset = null): Response
51
    {
52 1
        return $this->listEntities($this->get('rockparade.organizer_repository'), $limit, $offset);
53
    }
54
55
    /**
56
     * View organizer by name
57
     * @Route("/{id}", name="organizer_view")
58
     * @Method("GET")
59
     * @ApiDoc(
60
     *     section="Organizer",
61
     *     requirements={
62
     *         {
63
     *             "name"="id",
64
     *             "dataType"="string",
65
     *             "requirement"="true",
66
     *             "description"="organizer name"
67
     *         },
68
     *     },
69
     *     statusCodes={
70
     *         200="Organizer was found",
71
     *         404="Organizer with given name was not found",
72
     *     }
73
     * )
74
     * @param string $id organizer id
75
     */
76 3
    public function viewAction(string $id): Response
77
    {
78 3
        return $this->viewEntity($this->get('rockparade.organizer_repository'), $id);
79
    }
80
81
    /**
82
     * Create new organizer
83
     * @Route("", name="organizer_create")
84
     * @Method("POST")
85
     * @Security("has_role('ROLE_USER')")
86
     * @ApiDoc(
87
     *     section="Organizer",
88
     *     requirements={
89
     *         {
90
     *             "name"="name",
91
     *             "dataType"="string",
92
     *             "requirement"="true",
93
     *             "description"="organization name"
94
     *         },
95
     *         {
96
     *             "name"="description",
97
     *             "dataType"="string",
98
     *             "requirement"="true",
99
     *             "description"="organization description"
100
     *         },
101
     *         {
102
     *             "name"="members",
103
     *             "dataType"="array",
104
     *             "requirement"="false",
105
     *             "description"="logins and short descriptions of organization members"
106
     *         },
107
     *     },
108
     *     statusCodes={
109
     *         201="New organizer was created. Link to new resource provided in header 'Location'",
110
     *         400="Validation error",
111
     *     }
112
     * )
113
     */
114 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...
115
    {
116 2
        $form = $this->createAndProcessForm($request, OrganizerFormType::class);
117
118 2
        $apiResponseFactory = $this->get('rockparade.api_response_factory');
119 2
        $response = $apiResponseFactory->createResponse(
120 2
            $this->createApiOperation($request),
121
            $form,
122 2
            $this->getUser(),
123 2
            Organizer::class
124
        );
125
126 2
        return $this->respond($response);
127
    }
128
129
    /**
130
     * Add new member to organization
131
     * @Route("/{id}/members", name="organizer_member_create")
132
     * @Method("POST")
133
     * @Security("has_role('ROLE_USER')")
134
     * @ApiDoc(
135
     *     section="Organizer",
136
     *     requirements={
137
     *         {
138
     *             "name"="login",
139
     *             "dataType"="string",
140
     *             "requirement"="true",
141
     *             "description"="user login"
142
     *         },
143
     *         {
144
     *             "name"="short_description",
145
     *             "dataType"="string",
146
     *             "requirement"="true",
147
     *             "description"="short description of user role in organization"
148
     *         },
149
     *         {
150
     *             "name"="description",
151
     *             "dataType"="string",
152
     *             "requirement"="false",
153
     *             "description"="long description of user"
154
     *         },
155
     *     },
156
     *     statusCodes={
157
     *         201="Member was added to organization",
158
     *         400="Validation error",
159
     *     }
160
     * )
161
     * @param string $id organizer id
162
     */
163 1
    public function createMemberAction(string $id): Response
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
164
    {
165 1
        $response = new ApiValidationError('');
166
167 1
        return $this->respond($response);
168
    }
169
}
170