| Conditions | 6 |
| Paths | 5 |
| Total Lines | 78 |
| Code Lines | 47 |
| 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 |
||
| 53 | #[Route( |
||
| 54 | path: '/registration/gssf/{provider}/consume-assertion', |
||
| 55 | name: 'ss_registration_gssf_consume_assertion', |
||
| 56 | methods: ['POST'], |
||
| 57 | )] |
||
| 58 | public function consumeAssertion(Request $httpRequest, string $provider): array|Response |
||
| 59 | { |
||
| 60 | $this->checkerService->assertSecondFactorEnabled($provider); |
||
| 61 | |||
| 62 | $provider = $this->providerRepository->get($provider); |
||
| 63 | |||
| 64 | $this->logger->notice( |
||
| 65 | sprintf('Received GSSP "%s" SAMLResponse through Gateway, attempting to process', $provider->getName()) |
||
| 66 | ); |
||
| 67 | |||
| 68 | try { |
||
| 69 | $assertion = $this->postBinding->processResponse( |
||
| 70 | $httpRequest, |
||
| 71 | $provider->getRemoteIdentityProvider(), |
||
| 72 | $provider->getServiceProvider() |
||
| 73 | ); |
||
| 74 | } catch (Exception $exception) { |
||
| 75 | $provider->getStateHandler()->clear(); |
||
| 76 | |||
| 77 | $this->logger->error( |
||
| 78 | sprintf('Could not process received Response, error: "%s"', $exception->getMessage()) |
||
| 79 | ); |
||
| 80 | |||
| 81 | return $this->redirectToStatusReportForm( |
||
| 82 | $provider, |
||
| 83 | ['authenticationFailed' => true] |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | $expectedResponseTo = $provider->getStateHandler()->getRequestId(); |
||
| 88 | $provider->getStateHandler()->clear(); |
||
| 89 | |||
| 90 | if (!InResponseTo::assertEquals($assertion, $expectedResponseTo)) { |
||
| 91 | $this->logger->critical(sprintf( |
||
| 92 | 'Received Response with unexpected InResponseTo, %s', |
||
| 93 | ($expectedResponseTo ? 'expected "' . $expectedResponseTo . '"' : ' no response expected') |
||
| 94 | )); |
||
| 95 | |||
| 96 | return $this->redirectToStatusReportForm( |
||
| 97 | $provider, |
||
| 98 | ['authenticationFailed' => true] |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | |||
| 102 | $this->logger->notice( |
||
| 103 | sprintf('Processed GSSP "%s" SAMLResponse received through Gateway successfully', $provider->getName()) |
||
| 104 | ); |
||
| 105 | |||
| 106 | $gssfId = $this->attributeDictionary->translate($assertion)->getNameID(); |
||
| 107 | |||
| 108 | $secondFactorId = $this->gssfService->provePossession($this->getUser()->getIdentity()->id, $provider->getName(), $gssfId); |
||
| 109 | |||
| 110 | if ($secondFactorId) { |
||
| 111 | $this->logger->notice('GSSF possession has been proven successfully'); |
||
| 112 | |||
| 113 | if ($this->checkerService->emailVerificationIsRequired()) { |
||
| 114 | return $this->redirectToRoute( |
||
| 115 | 'ss_registration_email_verification_email_sent', |
||
| 116 | ['secondFactorId' => $secondFactorId] |
||
| 117 | ); |
||
| 118 | } else { |
||
| 119 | return $this->redirectToRoute( |
||
| 120 | 'ss_second_factor_vetting_types', |
||
| 121 | ['secondFactorId' => $secondFactorId] |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $this->logger->error('Unable to prove GSSF possession'); |
||
| 127 | |||
| 128 | return $this->redirectToStatusReportForm( |
||
| 129 | $provider, |
||
| 130 | ['proofOfPossessionFailed' => true] |
||
| 131 | ); |
||
| 145 |