| Conditions | 5 |
| Paths | 5 |
| Total Lines | 74 |
| Code Lines | 42 |
| 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 |
||
| 83 | public function consumeAssertionAction(Request $httpRequest, $provider) |
||
| 84 | { |
||
| 85 | $this->assertSecondFactorEnabled($provider); |
||
| 86 | |||
| 87 | $provider = $this->getProvider($provider); |
||
| 88 | |||
| 89 | $this->get('logger')->notice( |
||
| 90 | sprintf('Received GSSP "%s" SAMLResponse through Gateway, attempting to process', $provider->getName()) |
||
| 91 | ); |
||
| 92 | |||
| 93 | try { |
||
| 94 | /** @var \Surfnet\SamlBundle\Http\PostBinding $postBinding */ |
||
| 95 | $postBinding = $this->get('surfnet_saml.http.post_binding'); |
||
| 96 | $assertion = $postBinding->processResponse( |
||
| 97 | $httpRequest, |
||
| 98 | $provider->getRemoteIdentityProvider(), |
||
| 99 | $provider->getServiceProvider() |
||
| 100 | ); |
||
| 101 | } catch (Exception $exception) { |
||
| 102 | $provider->getStateHandler()->clear(); |
||
| 103 | |||
| 104 | $this->getLogger()->error( |
||
| 105 | sprintf('Could not process received Response, error: "%s"', $exception->getMessage()) |
||
| 106 | ); |
||
| 107 | |||
| 108 | return $this->renderInitiateForm( |
||
| 109 | $provider->getName(), |
||
| 110 | ['authenticationFailed' => true] |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | $expectedResponseTo = $provider->getStateHandler()->getRequestId(); |
||
| 115 | $provider->getStateHandler()->clear(); |
||
| 116 | |||
| 117 | if (!InResponseTo::assertEquals($assertion, $expectedResponseTo)) { |
||
| 118 | $this->getLogger()->critical(sprintf( |
||
| 119 | 'Received Response with unexpected InResponseTo, %s', |
||
| 120 | ($expectedResponseTo ? 'expected "' . $expectedResponseTo . '"' : ' no response expected') |
||
| 121 | )); |
||
| 122 | |||
| 123 | return $this->renderInitiateForm( |
||
| 124 | $provider->getName(), |
||
| 125 | ['authenticationFailed' => true] |
||
| 126 | ); |
||
| 127 | } |
||
| 128 | |||
| 129 | $this->get('logger')->notice( |
||
| 130 | sprintf('Processed GSSP "%s" SAMLResponse received through Gateway successfully', $provider->getName()) |
||
| 131 | ); |
||
| 132 | |||
| 133 | /** @var \Surfnet\StepupSelfService\SelfServiceBundle\Service\GssfService $service */ |
||
| 134 | $service = $this->get('surfnet_stepup_self_service_self_service.service.gssf'); |
||
| 135 | /** @var \Surfnet\SamlBundle\SAML2\Attribute\AttributeDictionary $attributeDictionary */ |
||
| 136 | $attributeDictionary = $this->get('surfnet_saml.saml.attribute_dictionary'); |
||
| 137 | $gssfId = $attributeDictionary->translate($assertion)->getNameID(); |
||
| 138 | |||
| 139 | $secondFactorId = $service->provePossession($this->getIdentity()->id, $provider->getName(), $gssfId); |
||
| 140 | |||
| 141 | if ($secondFactorId) { |
||
| 142 | $this->getLogger()->notice('GSSF possession has been proven successfully'); |
||
| 143 | |||
| 144 | return $this->redirectToRoute( |
||
| 145 | 'ss_registration_email_verification_email_sent', |
||
| 146 | ['secondFactorId' => $secondFactorId] |
||
| 147 | ); |
||
| 148 | } |
||
| 149 | |||
| 150 | $this->getLogger()->error('Unable to prove GSSF possession'); |
||
| 151 | |||
| 152 | return $this->renderInitiateForm( |
||
| 153 | $provider->getName(), |
||
| 154 | ['proofOfPossessionFailed' => true] |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | |||
| 231 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.