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