| Conditions | 10 | 
| Paths | 26 | 
| Total Lines | 77 | 
| 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  | 
            ||
| 88 | public function authenticate(TokenInterface $token)  | 
            ||
| 89 |     { | 
            ||
| 90 | $translatedAssertion = $this->attributeDictionary->translate($token->assertion);  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 91 | |||
| 92 | $nameId = $translatedAssertion->getNameID();  | 
            ||
| 93 |         $institution = $this->getSingleStringValue('schacHomeOrganization', $translatedAssertion); | 
            ||
| 94 | |||
| 95 | $identity = $this->identityService->findByNameIdAndInstitution($nameId, $institution);  | 
            ||
| 96 | |||
| 97 | // if no identity can be found, we're done.  | 
            ||
| 98 |         if ($identity === null) { | 
            ||
| 99 | throw new BadCredentialsException(  | 
            ||
| 100 | 'Unable to find Identity matching the criteria. Has the identity been registered before?'  | 
            ||
| 101 | );  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 | $raCredentials = $this->identityService->getRaCredentials($identity);  | 
            ||
| 105 | |||
| 106 | // if no credentials can be found, we're done.  | 
            ||
| 107 |         if (!$raCredentials) { | 
            ||
| 108 | throw new UserNotRaException(  | 
            ||
| 109 | 'The Identity is not registered as (S)RA(A) and therefor does not have access to this application'  | 
            ||
| 110 | );  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | // determine the role based on the credentials given  | 
            ||
| 114 | $roles = [];  | 
            ||
| 115 |         if ($raCredentials->isSraa) { | 
            ||
| 116 | $roles[] = 'ROLE_SRAA';  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 |         if ($raCredentials->isRaa) { | 
            ||
| 120 | $roles[] = 'ROLE_RAA';  | 
            ||
| 121 |         } else { | 
            ||
| 122 | $roles[] = 'ROLE_RA';  | 
            ||
| 123 | }  | 
            ||
| 124 | |||
| 125 | $institutionConfigurationOptions = $this->institutionConfigurationOptionsService  | 
            ||
| 126 | ->getInstitutionConfigurationOptionsFor($identity->institution);  | 
            ||
| 127 | |||
| 128 |         if ($institutionConfigurationOptions === null) { | 
            ||
| 129 | throw new InconsistentStateException(  | 
            ||
| 130 | sprintf(  | 
            ||
| 131 | 'InstitutionConfigurationOptions for institution "%s" '  | 
            ||
| 132 | . 'must exist but cannot be found after authenticating Identity "%s"',  | 
            ||
| 133 | $identity->institution,  | 
            ||
| 134 | $identity->id  | 
            ||
| 135 | )  | 
            ||
| 136 | );  | 
            ||
| 137 | }  | 
            ||
| 138 | |||
| 139 | // set the token  | 
            ||
| 140 | $authenticatedToken = new SamlToken($token->getLoa(), $roles, $institutionConfigurationOptions);  | 
            ||
| 141 | $authenticatedToken->setUser($identity);  | 
            ||
| 142 | |||
| 143 | // When dealing with a RA(A), determine for which institution the authenticating user should enter the RA environment  | 
            ||
| 144 |         if (!in_array('ROLE_SRAA', $roles)) { | 
            ||
| 145 | // Start by loading the ra listing for this identity to know what institutions (s)he is RA(A) for.  | 
            ||
| 146 | $institutions = $this->raListingService->searchBy($identity->id, $institution);  | 
            ||
| 147 |             if ($institutions->getTotalItems() === 1) { | 
            ||
| 148 | // Change the institution to the first item from the institution listing results  | 
            ||
| 149 | $institution = $institutions->getOnlyElement()->institution;  | 
            ||
| 150 |             } elseif ($institutions->getTotalItems() > 1) { | 
            ||
| 151 |                 if ($institutions->isListed($identity->institution)) { | 
            ||
| 152 | $institution = $identity->institution;  | 
            ||
| 153 |                 } else { | 
            ||
| 154 | // Otherwise pick the first institution in the list and set that for the  | 
            ||
| 155 | $institution = reset($institutions->getElements())->institution;  | 
            ||
| 156 | }  | 
            ||
| 157 |             } else { | 
            ||
| 158 |                 throw new AuthenticationException('Unauthorized to authenticate, user is not present in ra listing'); | 
            ||
| 159 | }  | 
            ||
| 160 | $authenticatedToken->changeInstitutionScope($institution, $institutionConfigurationOptions);  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 | return $authenticatedToken;  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 210 | 
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: