Conditions | 6 |
Paths | 10 |
Total Lines | 57 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 2 |
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 |
||
70 | public function authenticate(TokenInterface $token) |
||
71 | { |
||
72 | $translatedAssertion = $this->attributeDictionary->translate($token->assertion); |
||
73 | |||
74 | $nameId = $translatedAssertion->getNameID(); |
||
75 | $institution = $this->getSingleStringValue('schacHomeOrganization', $translatedAssertion); |
||
76 | |||
77 | $identity = $this->identityService->findByNameIdAndInstitution($nameId, $institution); |
||
78 | |||
79 | // if no identity can be found, we're done. |
||
80 | if ($identity === null) { |
||
81 | throw new BadCredentialsException( |
||
82 | 'Unable to find Identity matching the criteria. Has the identity been registered before?' |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | $raCredentials = $this->identityService->getRaCredentials($identity); |
||
87 | |||
88 | // if no credentials can be found, we're done. |
||
89 | if (!$raCredentials) { |
||
90 | throw new BadCredentialsException( |
||
91 | 'The Identity is not registered as (S)RA(A) and therefor does not have access to this application' |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | // determine the role based on the credentials given |
||
96 | $roles = []; |
||
97 | if ($raCredentials->isSraa) { |
||
98 | $roles[] = 'ROLE_SRAA'; |
||
99 | } |
||
100 | |||
101 | if ($raCredentials->isRaa) { |
||
102 | $roles[] = 'ROLE_RAA'; |
||
103 | } else { |
||
104 | $roles[] = 'ROLE_RA'; |
||
105 | } |
||
106 | |||
107 | $institutionConfigurationOptions = $this->institutionConfigurationOptionsService |
||
108 | ->getInstitutionConfigurationOptionsFor($identity->institution); |
||
109 | |||
110 | if ($institutionConfigurationOptions === null) { |
||
111 | throw new InconsistentStateException( |
||
112 | sprintf( |
||
113 | 'InstitutionConfigurationOptions for institution "%s" ' |
||
114 | . 'must exist but cannot be found after authenticating Identity "%s"', |
||
115 | $identity->institution, |
||
116 | $identity->id |
||
117 | ) |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | // set the token |
||
122 | $authenticatedToken = new SamlToken($token->getLoa(), $roles, $institutionConfigurationOptions); |
||
123 | $authenticatedToken->setUser($identity); |
||
124 | |||
125 | return $authenticatedToken; |
||
126 | } |
||
127 | |||
167 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.