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