This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ApiBundle\Controller; |
||
4 | |||
5 | use FOS\RestBundle\Controller\Annotations\QueryParam; |
||
6 | use FOS\RestBundle\Controller\Annotations\RouteResource; |
||
7 | use FOS\RestBundle\Controller\FOSRestController; |
||
8 | use FOS\RestBundle\Request\ParamFetcher; |
||
9 | use Maxpou\BeerBundle\Entity\Beer; |
||
10 | use Maxpou\BeerBundle\Form\Type\BeerApiType; |
||
11 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
||
12 | use Symfony\Component\HttpFoundation\Request; |
||
13 | use Symfony\Component\HttpFoundation\Response; |
||
14 | use Symfony\Component\HttpKernel\Exception\HttpException; |
||
15 | |||
16 | /** |
||
17 | * Beer controller. |
||
18 | * |
||
19 | * @RouteResource("beer") |
||
20 | */ |
||
21 | class BeerController extends FOSRestController |
||
22 | { |
||
23 | /** |
||
24 | * Get all Beers entities. |
||
25 | * |
||
26 | * @ApiDoc( |
||
27 | * statusCodes={ |
||
28 | * 200="Returned when successful" |
||
29 | * }) |
||
30 | * @QueryParam(name="offset", requirements="\d+", nullable=true, |
||
31 | * description="Offset from which to start listing breweries.") |
||
32 | * @QueryParam(name="limit", requirements="\d+", nullable=true, |
||
33 | * description="How many breweries to return.") |
||
34 | * |
||
35 | * @param UUID $breweryId Brewery Id |
||
36 | */ |
||
37 | public function cgetAction($breweryId, ParamFetcher $paramFetcher) |
||
38 | { |
||
39 | $offset = $paramFetcher->get('offset'); |
||
40 | $limit = $paramFetcher->get('limit'); |
||
41 | |||
42 | $em = $this->getDoctrine()->getManager(); |
||
43 | $beers = $em->getRepository('MaxpouBeerBundle:Beer') |
||
44 | ->findBy( |
||
45 | ['brewery' => $breweryId], |
||
46 | ['name' => 'ASC'], |
||
47 | $limit, |
||
48 | $offset |
||
49 | ); |
||
50 | |||
51 | return $beers; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get a Beer entity. |
||
56 | * |
||
57 | * @ApiDoc( |
||
58 | * statusCodes={ |
||
59 | * 200="Returned when successful", |
||
60 | * 404="Returned when not found" |
||
61 | * }) |
||
62 | * |
||
63 | * @param UUID $breweryId Brewery Id |
||
64 | * @param UUID $beerId Beer Id |
||
65 | */ |
||
66 | View Code Duplication | public function getAction($breweryId, $beerId) |
|
0 ignored issues
–
show
|
|||
67 | { |
||
68 | $brewery = $this->getDoctrine()->getManager() |
||
69 | ->getRepository('MaxpouBeerBundle:Brewery') |
||
70 | ->find($breweryId); |
||
71 | |||
72 | if (!$brewery) { |
||
73 | throw new HttpException(404, 'Unable to find this Brewery entity'); |
||
74 | } |
||
75 | |||
76 | $beer = $this->getDoctrine()->getManager() |
||
77 | ->getRepository('MaxpouBeerBundle:Beer') |
||
78 | ->find($beerId); |
||
79 | |||
80 | if (!$beer) { |
||
81 | throw new HttpException(404, 'Unable to find this Beer entity'); |
||
82 | } |
||
83 | |||
84 | return $beer; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Add a Beer. |
||
89 | * |
||
90 | * @ApiDoc( |
||
91 | * statusCodes={ |
||
92 | * 201="Returned when successful", |
||
93 | * 400="Returned when parameter is wrong" |
||
94 | * }, |
||
95 | * input = { |
||
96 | * "class" = "Maxpou\BeerBundle\Form\Type\BeerApiType", |
||
97 | * "name" = "" |
||
98 | * }) |
||
99 | * |
||
100 | * @param UUID $breweryId Brewery Id |
||
101 | */ |
||
102 | public function postAction($breweryId, Request $request) |
||
103 | { |
||
104 | $brewery = $this->getDoctrine()->getManager() |
||
105 | ->getRepository('MaxpouBeerBundle:Brewery') |
||
106 | ->find($breweryId); |
||
107 | |||
108 | if (!$brewery) { |
||
109 | throw new HttpException(404, 'Unable to find this Brewery entity'); |
||
110 | } |
||
111 | |||
112 | $beer = new Beer(); |
||
113 | $beer->setBrewery($brewery); |
||
114 | |||
115 | $form = $this->createForm(BeerApiType::class, $beer); |
||
116 | $form->handleRequest($request); |
||
117 | |||
118 | if ($form->isValid()) { |
||
119 | $em = $this->getDoctrine()->getManager(); |
||
120 | $em->persist($beer); |
||
121 | $em->flush(); |
||
122 | |||
123 | $view = $this->view($beer, 201); |
||
124 | } else { |
||
125 | $view = $this->view($form, 400); |
||
126 | } |
||
127 | |||
128 | return $this->handleView($view); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Update an existing Beer (cannot create here, sorry). |
||
133 | * |
||
134 | * @ApiDoc( |
||
135 | * statusCodes={ |
||
136 | * 204="Returned when successful", |
||
137 | * 404="Returned when not found", |
||
138 | * 400="Returned when parameter is wrong" |
||
139 | * }, |
||
140 | * input = { |
||
141 | * "class" = "Maxpou\BeerBundle\Form\Type\BeerApiType", |
||
142 | * "name" = "" |
||
143 | * }) |
||
144 | * |
||
145 | * @param UUID $breweryId Brewery Id |
||
146 | * @param UUID $beerId Beer Id |
||
147 | */ |
||
148 | View Code Duplication | public function putAction($breweryId, Request $request, $beerId) |
|
0 ignored issues
–
show
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. ![]() |
|||
149 | { |
||
150 | $beer = $this->getDoctrine()->getManager() |
||
151 | ->getRepository('MaxpouBeerBundle:Beer') |
||
152 | ->find($beerId); |
||
153 | |||
154 | if (!$beer) { |
||
155 | throw new HttpException(404, 'Unable to find this Beer entity'); |
||
156 | } |
||
157 | |||
158 | $form = $this->createForm(BeerApiType::class, $beer); |
||
159 | $form->submit($request->request->all()); |
||
160 | |||
161 | if ($form->isValid()) { |
||
162 | $em = $this->getDoctrine()->getManager(); |
||
163 | $em->persist($beer); |
||
164 | $em->flush(); |
||
165 | |||
166 | $view = $this->view(null, 204); |
||
167 | |||
168 | return $this->handleView($view); |
||
169 | } else { |
||
170 | $view = $this->view($form, 400); |
||
171 | } |
||
172 | |||
173 | return $view; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Delete brewery. |
||
178 | * |
||
179 | * @ApiDoc( |
||
180 | * statusCodes={ |
||
181 | * 204="Returned when successful" |
||
182 | * }) |
||
183 | * |
||
184 | * @param UUID $breweryId Brewery Id |
||
185 | * @param UUID $beerId Beer Id |
||
186 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
187 | */ |
||
188 | public function deleteAction($breweryId, $beerId) |
||
0 ignored issues
–
show
|
|||
189 | { |
||
190 | $beer = $this->getDoctrine()->getManager() |
||
191 | ->getRepository('MaxpouBeerBundle:Beer') |
||
192 | ->find($beerId); |
||
193 | |||
194 | if ($beer) { |
||
195 | $em = $this->getDoctrine()->getManager(); |
||
196 | $em->remove($beer); |
||
197 | $em->flush(); |
||
198 | } |
||
199 | |||
200 | return $this->view(null, 204); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Delete all beers from an existing brewery entity. |
||
205 | * |
||
206 | * @ApiDoc( |
||
207 | * statusCodes={ |
||
208 | * 204="Returned when successful" |
||
209 | * }) |
||
210 | * |
||
211 | * @param UUID $breweryId Brewery Id |
||
212 | */ |
||
213 | View Code Duplication | public function cdeleteAction($breweryId) |
|
0 ignored issues
–
show
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. ![]() |
|||
214 | { |
||
215 | $em = $this->getDoctrine()->getManager(); |
||
216 | $brewery = $em->getRepository('MaxpouBeerBundle:Brewery') |
||
217 | ->find($breweryId); |
||
218 | |||
219 | if (!$brewery) { |
||
220 | throw new HttpException(404, 'Unable to find this Brewery entity'); |
||
221 | } |
||
222 | |||
223 | $em->getRepository('MaxpouBeerBundle:Beer') |
||
224 | ->deleteAll($brewery); |
||
225 | |||
226 | return $this->view(null, 204); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * Options. |
||
231 | * |
||
232 | * @ApiDoc( |
||
233 | * statusCodes={ |
||
234 | * 200="Returned when successful" |
||
235 | * }) |
||
236 | * |
||
237 | * @param UUID $breweryId Brewery Id |
||
238 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
239 | */ |
||
240 | public function coptionsAction($breweryId) |
||
0 ignored issues
–
show
|
|||
241 | { |
||
242 | $response = new Response(); |
||
243 | $response->headers->set('Allow', 'OPTIONS, GET, POST, DELETE'); |
||
244 | |||
245 | return $response; |
||
246 | } |
||
247 | } |
||
248 |
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.