Conditions | 9 |
Paths | 14 |
Total Lines | 58 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
94 | public function revokeAction(Request $request, $state, $secondFactorId) |
||
95 | { |
||
96 | $identity = $this->getIdentity(); |
||
97 | |||
98 | /** @var SecondFactorService $service */ |
||
99 | $service = $this->get('surfnet_stepup_self_service_self_service.service.second_factor'); |
||
100 | if (!$service->identityHasSecondFactorOfStateWithId($identity->id, $state, $secondFactorId)) { |
||
101 | $this->get('logger')->error(sprintf( |
||
102 | 'Identity "%s" tried to revoke "%s" second factor "%s", but does not own that second factor', |
||
103 | $identity->id, |
||
104 | $state, |
||
105 | $secondFactorId |
||
106 | )); |
||
107 | throw new NotFoundHttpException(); |
||
108 | } |
||
109 | |||
110 | switch ($state) { |
||
111 | case 'unverified': |
||
112 | $secondFactor = $service->findOneUnverified($secondFactorId); |
||
113 | break; |
||
114 | case 'verified': |
||
115 | $secondFactor = $service->findOneVerified($secondFactorId); |
||
116 | break; |
||
117 | case 'vetted': |
||
118 | $secondFactor = $service->findOneVetted($secondFactorId); |
||
119 | break; |
||
120 | default: |
||
121 | throw new LogicException('There are no other types of second factor.'); |
||
|
|||
122 | } |
||
123 | |||
124 | if ($secondFactor === null) { |
||
125 | throw new NotFoundHttpException( |
||
126 | sprintf("No %s second factor with id '%s' exists.", $state, $secondFactorId) |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | $command = new RevokeCommand(); |
||
131 | $command->identity = $identity; |
||
132 | $command->secondFactor = $secondFactor; |
||
133 | |||
134 | $form = $this->createForm(RevokeSecondFactorType::class, $command)->handleRequest($request); |
||
135 | |||
136 | if ($form->isSubmitted() && $form->isValid()) { |
||
137 | /** @var FlashBagInterface $flashBag */ |
||
138 | $flashBag = $this->get('session')->getFlashBag(); |
||
139 | |||
140 | if ($service->revoke($command)) { |
||
141 | $flashBag->add('success', 'ss.second_factor.revoke.alert.revocation_successful'); |
||
142 | } else { |
||
143 | $flashBag->add('error', 'ss.second_factor.revoke.alert.revocation_failed'); |
||
144 | } |
||
145 | |||
146 | return $this->redirectToRoute('ss_second_factor_list'); |
||
147 | } |
||
148 | |||
149 | return [ |
||
150 | 'form' => $form->createView(), |
||
151 | 'secondFactor' => $secondFactor, |
||
152 | ]; |
||
155 |