| Conditions | 11 |
| Paths | 12 |
| Total Lines | 46 |
| 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 |
||
| 78 | public function authenticate(TokenInterface $token) |
||
| 79 | { |
||
| 80 | $translatedAssertion = $this->attributeDictionary->translate($token->assertion); |
||
|
|
|||
| 81 | |||
| 82 | $nameId = $translatedAssertion->getNameID(); |
||
| 83 | $institution = $this->getSingleStringValue('schacHomeOrganization', $translatedAssertion); |
||
| 84 | $identity = $this->identityService->findByNameIdAndInstitution($nameId, $institution); |
||
| 85 | |||
| 86 | // if no identity can be found, we're done. |
||
| 87 | if ($identity === null) { |
||
| 88 | throw new BadCredentialsException( |
||
| 89 | 'Unable to find Identity matching the criteria. Has the identity been registered before?' |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | |||
| 93 | $profile = $this->profileService->findByIdentityId($identity->id); |
||
| 94 | |||
| 95 | // if no credentials can be found, we're done. |
||
| 96 | if (!$profile->isSraa && empty($profile->authorizations) && empty($profile->management)) { |
||
| 97 | throw new UserNotRaException( |
||
| 98 | 'The Identity is not registered as (S)RA(A) and therefor does not have access to this application' |
||
| 99 | ); |
||
| 100 | } |
||
| 101 | |||
| 102 | // determine the role based on the credentials given |
||
| 103 | $roles = []; |
||
| 104 | if ($profile->isSraa) { |
||
| 105 | $roles[] = 'ROLE_SRAA'; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Get authorizations (explicit RA(A) roles use_ra/use_raa). |
||
| 109 | foreach ($profile->authorizations as $institution => $role) { |
||
| 110 | if ($role[0] == 'raa' && !in_array('ROLE_RAA', $roles)) { |
||
| 111 | $roles[] = 'ROLE_RAA'; |
||
| 112 | } |
||
| 113 | if ($role[0] == 'ra' && !in_array('ROLE_RA', $roles)) { |
||
| 114 | $roles[] = 'ROLE_RA'; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | // set the token |
||
| 119 | $authenticatedToken = new SamlToken($token->getLoa(), $roles); |
||
| 120 | $authenticatedToken->setUser($identity); |
||
| 121 | |||
| 122 | return $authenticatedToken; |
||
| 123 | } |
||
| 124 | |||
| 169 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: