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 AppBundle\Controller; |
||
4 | |||
5 | use Symfony\Component\HttpFoundation\Request; |
||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
||
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
||
9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
10 | use AppBundle\Entity\CustomUser; |
||
11 | use AppBundle\Form\Type\CustomUserType; |
||
12 | |||
13 | /** |
||
14 | * CustomUser controller. |
||
15 | * |
||
16 | * @Route("/cms/user") |
||
17 | */ |
||
18 | class CustomUserController extends Controller |
||
0 ignored issues
–
show
|
|||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Lists all CustomUser entities. |
||
23 | * |
||
24 | * @Route("/", name="cms_user") |
||
25 | * @Method("GET") |
||
26 | * @Template() |
||
27 | */ |
||
28 | public function indexAction() |
||
29 | { |
||
30 | $em = $this->getDoctrine()->getManager(); |
||
31 | |||
32 | $entities = $em->getRepository('AppBundle:CustomUser')->findAll(); |
||
33 | |||
34 | return array( |
||
35 | 'entities' => $entities, |
||
36 | ); |
||
37 | } |
||
38 | /** |
||
39 | * Creates a new CustomUser entity. |
||
40 | * |
||
41 | * @Route("/", name="cms_user_create") |
||
42 | * @Method("POST") |
||
43 | * @Template("AppBundle:CustomUser:new.html.twig") |
||
44 | */ |
||
45 | public function createAction(Request $request) |
||
46 | { |
||
47 | $entity = new CustomUser(); |
||
48 | $form = $this->createCreateForm($entity); |
||
49 | $form->handleRequest($request); |
||
50 | |||
51 | if ($form->isValid()) { |
||
52 | $em = $this->getDoctrine()->getManager(); |
||
53 | $em->persist($entity); |
||
54 | $em->flush(); |
||
55 | |||
56 | return $this->redirect($this->generateUrl('cms_user_show', array('id' => $entity->getId()))); |
||
57 | } |
||
58 | |||
59 | return array( |
||
60 | 'entity' => $entity, |
||
61 | 'form' => $form->createView(), |
||
62 | ); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Creates a form to create a CustomUser entity. |
||
67 | * |
||
68 | * @param CustomUser $entity The entity |
||
69 | * |
||
70 | * @return \Symfony\Component\Form\Form The form |
||
71 | */ |
||
72 | private function createCreateForm(CustomUser $entity) |
||
73 | { |
||
74 | $form = $this->createForm(new CustomUserType(), $entity, array( |
||
75 | 'action' => $this->generateUrl('cms_user_create'), |
||
76 | 'method' => 'POST', |
||
77 | )); |
||
78 | |||
79 | $form->add('submit', 'submit', array('label' => 'Create')); |
||
80 | |||
81 | return $form; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Displays a form to create a new CustomUser entity. |
||
86 | * |
||
87 | * @Route("/new", name="cms_user_new") |
||
88 | * @Method("GET") |
||
89 | * @Template() |
||
90 | */ |
||
91 | public function newAction() |
||
92 | { |
||
93 | $entity = new CustomUser(); |
||
94 | $form = $this->createCreateForm($entity); |
||
95 | |||
96 | return array( |
||
97 | 'entity' => $entity, |
||
98 | 'form' => $form->createView(), |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Finds and displays a CustomUser entity. |
||
104 | * |
||
105 | * @Route("/{id}", name="cms_user_show") |
||
106 | * @Method("GET") |
||
107 | * @Template() |
||
108 | */ |
||
109 | public function showAction($id) |
||
110 | { |
||
111 | $em = $this->getDoctrine()->getManager(); |
||
112 | |||
113 | $entity = $em->getRepository('AppBundle:CustomUser')->find($id); |
||
114 | |||
115 | if (!$entity) { |
||
116 | throw $this->createNotFoundException('Unable to find CustomUser entity.'); |
||
117 | } |
||
118 | |||
119 | $deleteForm = $this->createDeleteForm($id); |
||
120 | |||
121 | return array( |
||
122 | 'entity' => $entity, |
||
123 | 'delete_form' => $deleteForm->createView(), |
||
124 | ); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Displays a form to edit an existing CustomUser entity. |
||
129 | * |
||
130 | * @Route("/{id}/edit", name="cms_user_edit") |
||
131 | * @Method("GET") |
||
132 | * @Template() |
||
133 | */ |
||
134 | public function editAction($id) |
||
135 | { |
||
136 | $em = $this->getDoctrine()->getManager(); |
||
137 | |||
138 | $entity = $em->getRepository('AppBundle:CustomUser')->find($id); |
||
139 | |||
140 | if (!$entity) { |
||
141 | throw $this->createNotFoundException('Unable to find CustomUser entity.'); |
||
142 | } |
||
143 | |||
144 | $editForm = $this->createEditForm($entity); |
||
145 | $deleteForm = $this->createDeleteForm($id); |
||
146 | |||
147 | return array( |
||
148 | 'entity' => $entity, |
||
149 | 'edit_form' => $editForm->createView(), |
||
150 | 'delete_form' => $deleteForm->createView(), |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Creates a form to edit a CustomUser entity. |
||
156 | * |
||
157 | * @param CustomUser $entity The entity |
||
158 | * |
||
159 | * @return \Symfony\Component\Form\Form The form |
||
160 | */ |
||
161 | private function createEditForm(CustomUser $entity) |
||
162 | { |
||
163 | $form = $this->createForm(new CustomUserType(), $entity, array( |
||
164 | 'action' => $this->generateUrl('cms_user_update', array('id' => $entity->getId())), |
||
165 | 'method' => 'PUT', |
||
166 | )); |
||
167 | |||
168 | $form->add('submit', 'submit', array('label' => 'Update')); |
||
169 | |||
170 | return $form; |
||
171 | } |
||
172 | /** |
||
173 | * Edits an existing CustomUser entity. |
||
174 | * |
||
175 | * @Route("/{id}", name="cms_user_update") |
||
176 | * @Method("PUT") |
||
177 | * @Template("AppBundle:CustomUser:edit.html.twig") |
||
178 | */ |
||
179 | public function updateAction(Request $request, $id) |
||
180 | { |
||
181 | $em = $this->getDoctrine()->getManager(); |
||
182 | |||
183 | $entity = $em->getRepository('AppBundle:CustomUser')->find($id); |
||
184 | |||
185 | if (!$entity) { |
||
186 | throw $this->createNotFoundException('Unable to find CustomUser entity.'); |
||
187 | } |
||
188 | |||
189 | $deleteForm = $this->createDeleteForm($id); |
||
190 | $editForm = $this->createEditForm($entity); |
||
191 | $editForm->handleRequest($request); |
||
192 | |||
193 | if ($editForm->isValid()) { |
||
194 | $em->flush(); |
||
195 | |||
196 | return $this->redirect($this->generateUrl('cms_user_edit', array('id' => $id))); |
||
197 | } |
||
198 | |||
199 | return array( |
||
200 | 'entity' => $entity, |
||
201 | 'edit_form' => $editForm->createView(), |
||
202 | 'delete_form' => $deleteForm->createView(), |
||
203 | ); |
||
204 | } |
||
205 | /** |
||
206 | * Deletes a CustomUser entity. |
||
207 | * |
||
208 | * @Route("/{id}", name="cms_user_delete") |
||
209 | * @Method("DELETE") |
||
210 | */ |
||
211 | public function deleteAction(Request $request, $id) |
||
212 | { |
||
213 | $form = $this->createDeleteForm($id); |
||
214 | $form->handleRequest($request); |
||
215 | |||
216 | if ($form->isValid()) { |
||
217 | $em = $this->getDoctrine()->getManager(); |
||
218 | $entity = $em->getRepository('AppBundle:CustomUser')->find($id); |
||
219 | |||
220 | if (!$entity) { |
||
221 | throw $this->createNotFoundException('Unable to find CustomUser entity.'); |
||
222 | } |
||
223 | |||
224 | $em->remove($entity); |
||
225 | $em->flush(); |
||
226 | } |
||
227 | |||
228 | return $this->redirect($this->generateUrl('cms_user')); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Creates a form to delete a CustomUser entity by id. |
||
233 | * |
||
234 | * @param mixed $id The entity id |
||
235 | * |
||
236 | * @return \Symfony\Component\Form\Form The form |
||
237 | */ |
||
238 | private function createDeleteForm($id) |
||
239 | { |
||
240 | return $this->createFormBuilder() |
||
241 | ->setAction($this->generateUrl('cms_user_delete', array('id' => $id))) |
||
242 | ->setMethod('DELETE') |
||
243 | ->add('submit', 'submit', array('label' => 'Delete')) |
||
244 | ->getForm() |
||
245 | ; |
||
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.