Conditions | 3 |
Paths | 3 |
Total Lines | 57 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function settingsAction(Request $request, Application $app) |
||
49 | { |
||
50 | $data = array(); |
||
51 | |||
52 | $form = $app['form.factory']->create( |
||
53 | new SettingsType(), |
||
54 | $app['user'] |
||
55 | ); |
||
56 | |||
57 | // IMPORTANT Security fix! |
||
58 | $currentUserUsername = $app['user']->getUsername(); |
||
59 | |||
60 | if ($request->getMethod() == 'POST') { |
||
61 | $form->handleRequest($request); |
||
62 | |||
63 | // IMPORTANT Security fix! |
||
64 | /* |
||
65 | * Some weird bug here allows to impersonate to another user |
||
66 | * by just changing to his (like some admins) username |
||
67 | * (after failed "username already used" message) |
||
68 | * when the validation kicks in, and one refresh later, |
||
69 | * you're logged in as that user. |
||
70 | */ |
||
71 | $app['user']->setUsername($currentUserUsername); |
||
72 | |||
73 | if ($form->isValid()) { |
||
74 | $userEntity = $form->getData(); |
||
75 | |||
76 | /*** Image ***/ |
||
77 | $userEntity |
||
78 | ->getProfile() |
||
79 | ->setImageUploadPath($app['baseUrl'].'/assets/uploads/') |
||
80 | ->setImageUploadDir(WEB_DIR.'/assets/uploads/') |
||
81 | ->imageUpload() |
||
82 | ; |
||
83 | |||
84 | $app['orm.em']->persist($userEntity); |
||
85 | $app['orm.em']->flush(); |
||
86 | |||
87 | $app['flashbag']->add( |
||
88 | 'success', |
||
89 | $app['translator']->trans( |
||
90 | 'members-area.my.settings.successText' |
||
91 | ) |
||
92 | ); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | $data['form'] = $form->createView(); |
||
97 | |||
98 | return new Response( |
||
99 | $app['twig']->render( |
||
100 | 'contents/members-area/my/settings.html.twig', |
||
101 | $data |
||
102 | ) |
||
103 | ); |
||
104 | } |
||
105 | |||
156 |