Conditions | 11 |
Paths | 10 |
Total Lines | 95 |
Code Lines | 59 |
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 |
||
52 | public function startProcedureAction(Request $request) |
||
53 | { |
||
54 | $this->denyAccessUnlessGranted(['ROLE_RA']); |
||
55 | $logger = $this->get('logger'); |
||
56 | |||
57 | $logger->notice('Vetting Procedure Search started'); |
||
58 | |||
59 | $command = new StartVettingProcedureCommand(); |
||
60 | |||
61 | $form = $this->createForm('ra_start_vetting_procedure', $command)->handleRequest($request); |
||
62 | |||
63 | if (!$form->isValid()) { |
||
64 | $logger->notice('No search submitted, displaying search by registration code form'); |
||
65 | |||
66 | return ['form' => $form->createView()]; |
||
67 | } |
||
68 | |||
69 | $secondFactor = $this->getSecondFactorService() |
||
70 | ->findVerifiedSecondFactorByRegistrationCode($command->registrationCode); |
||
71 | |||
72 | if ($secondFactor === null) { |
||
73 | $form->addError(new FormError('ra.form.start_vetting_procedure.unknown_registration_code')); |
||
74 | $logger->notice('Cannot start new vetting procedure, no second factor found'); |
||
75 | |||
76 | return ['form' => $form->createView()]; |
||
77 | } |
||
78 | |||
79 | if (!$this->isGranted('ROLE_SRAA') && $secondFactor->institution !== $this->getIdentity()->institution) { |
||
80 | $form->addError(new FormError('ra.form.start_vetting_procedure.different_institution_error')); |
||
81 | $logger->notice( |
||
82 | 'Cannot start new vetting procedure, registrant belongs to a different institution than RA' |
||
83 | ); |
||
84 | |||
85 | return ['form' => $form->createView()]; |
||
86 | } |
||
87 | |||
88 | $enabledSecondFactors = $this->container->getParameter('surfnet_stepup_ra.enabled_second_factors'); |
||
89 | if (!in_array($secondFactor->type, $enabledSecondFactors, true)) { |
||
90 | $logger->warning( |
||
91 | sprintf( |
||
92 | 'An RA attempted vetting of disabled second factor "%s" of type "%s"', |
||
93 | $secondFactor->id, |
||
94 | $secondFactor->type |
||
95 | ) |
||
96 | ); |
||
97 | |||
98 | return $this |
||
99 | ->render( |
||
100 | 'SurfnetStepupRaRaBundle:Vetting:secondFactorTypeDisabled.html.twig', |
||
101 | ['secondFactorType' => $secondFactor->type] |
||
102 | ) |
||
103 | ->setStatusCode(Response::HTTP_BAD_REQUEST); |
||
104 | } |
||
105 | |||
106 | /** @var SamlToken $token */ |
||
107 | $token = $this->get('security.token_storage')->getToken(); |
||
108 | $command->authorityId = $this->getIdentity()->id; |
||
109 | $command->authorityLoa = $token->getLoa(); |
||
110 | $command->secondFactor = $secondFactor; |
||
|
|||
111 | |||
112 | if (!$this->getVettingService()->isLoaSufficientToStartProcedure($command)) { |
||
113 | $form->addError(new FormError('ra.form.start_vetting_procedure.loa_insufficient')); |
||
114 | |||
115 | $logger->notice('Cannot start new vetting procedure, Authority LoA is insufficient'); |
||
116 | |||
117 | return ['form' => $form->createView()]; |
||
118 | } |
||
119 | |||
120 | $procedureId = $this->getVettingService()->startProcedure($command); |
||
121 | |||
122 | $this->get('ra.procedure_logger') |
||
123 | ->forProcedure($procedureId) |
||
124 | ->notice(sprintf('Starting new Vetting Procedure for second factor of type "%s"', $secondFactor->type)); |
||
125 | |||
126 | $secondFactorType = new SecondFactorType($secondFactor->type); |
||
127 | if ($secondFactorType->isYubikey()) { |
||
128 | return $this->redirectToRoute('ra_vetting_yubikey_verify', ['procedureId' => $procedureId]); |
||
129 | } elseif ($secondFactorType->isSms()) { |
||
130 | return $this->redirectToRoute('ra_vetting_sms_send_challenge', ['procedureId' => $procedureId]); |
||
131 | } elseif ($this->getSecondFactorTypeService()->isGssf($secondFactorType)) { |
||
132 | return $this->redirectToRoute( |
||
133 | 'ra_vetting_gssf_initiate', |
||
134 | [ |
||
135 | 'procedureId' => $procedureId, |
||
136 | 'provider' => $secondFactor->type |
||
137 | ] |
||
138 | ); |
||
139 | } elseif ($secondFactorType->isU2f()) { |
||
140 | return $this->redirectToRoute('ra_vetting_u2f_start_authentication', ['procedureId' => $procedureId]); |
||
141 | } else { |
||
142 | throw new RuntimeException( |
||
143 | sprintf('RA does not support vetting procedure for second factor type "%s"', $secondFactor->type) |
||
144 | ); |
||
145 | } |
||
146 | } |
||
147 | |||
302 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.