| Conditions | 2 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 31 |
| 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 |
||
| 29 | public function selectInstitutionAction(Request $request) |
||
| 30 | { |
||
| 31 | $this->denyAccessUnlessGranted(['ROLE_SRAA']); |
||
| 32 | |||
| 33 | $logger = $this->get('logger'); |
||
| 34 | /** @var Identity $identity */ |
||
| 35 | $identity = $this->get('security.token_storage')->getToken()->getUser(); |
||
| 36 | |||
| 37 | $logger->notice(sprintf('Select Institution for SRAA "%s"', $identity->id)); |
||
| 38 | |||
| 39 | $command = new SelectInstitutionCommand(); |
||
| 40 | $command->institution = $identity->institution; |
||
| 41 | |||
| 42 | $form = $this->createForm('sraa_institution_select', $command); |
||
| 43 | $form->handleRequest($request); |
||
| 44 | |||
| 45 | if ($form->isValid()) { |
||
| 46 | $newInstitution = $command->institution; |
||
| 47 | $identity->institution = $newInstitution; |
||
| 48 | |||
| 49 | /** @var SamlToken $token */ |
||
| 50 | $tokenStorage = $this->get('security.token_storage'); |
||
| 51 | $token = $tokenStorage->getToken(); |
||
| 52 | |||
| 53 | $institutionConfigurationOptionsService = $this->get('ra.service.institution_configuration_options'); |
||
|
|
|||
| 54 | $institutionConfigurationOptions = $institutionConfigurationOptionsService |
||
| 55 | ->getInstitutionConfigurationOptionsFor($newInstitution); |
||
| 56 | |||
| 57 | // The institution configuration options need to be updated to correctly acquire the context of the |
||
| 58 | // selected institution |
||
| 59 | $token->setInstitutionConfigurationOptions($institutionConfigurationOptions); |
||
| 60 | $tokenStorage->setToken($token); |
||
| 61 | |||
| 62 | $flashMessage = $this->get('translator') |
||
| 63 | ->trans('ra.sraa.changed_institution', ['%institution%' => $newInstitution]); |
||
| 64 | |||
| 65 | $this->get('session')->getFlashBag()->add('success', $flashMessage); |
||
| 66 | |||
| 67 | $logger->notice(sprintf( |
||
| 68 | 'SRAA "%s successfully switched to institution "%s"', |
||
| 69 | $identity->id, |
||
| 70 | $newInstitution |
||
| 71 | )); |
||
| 72 | |||
| 73 | return $this->redirect($this->generateUrl('ra_vetting_search')); |
||
| 74 | } |
||
| 75 | |||
| 76 | $logger->notice(sprintf('Showing select institution form for SRAA "%s"', $identity->id)); |
||
| 77 | |||
| 78 | return $this->render( |
||
| 79 | 'SurfnetStepupRaRaBundle:Sraa:selectInstitution.html.twig', |
||
| 80 | ['form' => $form->createView()] |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.