| Conditions | 13 | 
| Paths | 32 | 
| Total Lines | 78 | 
| Code Lines | 44 | 
| Lines | 28 | 
| Ratio | 35.9 % | 
| 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  | 
            ||
| 87 | public function authenticate(array $data, HTTPRequest $request, ValidationResult &$result = null)  | 
            ||
| 88 |     { | 
            ||
| 89 |         if (is_null($result)) { | 
            ||
| 90 | $result = new ValidationResult();  | 
            ||
| 91 | }  | 
            ||
| 92 | /** @var LDAPService $service */  | 
            ||
| 93 | $service = Injector::inst()->get(LDAPService::class);  | 
            ||
| 94 | $login = trim($data['Login']);  | 
            ||
| 95 |         if (Email::is_valid_address($login)) { | 
            ||
| 96 |             if (Config::inst()->get(self::class, 'allow_email_login') != 'yes') { | 
            ||
| 97 | $result->addError(  | 
            ||
| 98 | _t(  | 
            ||
| 99 | 'LDAPAuthenticator.PLEASEUSEUSERNAME',  | 
            ||
| 100 | 'Please enter your username instead of your email to log in.'  | 
            ||
| 101 | )  | 
            ||
| 102 | );  | 
            ||
| 103 | return null;  | 
            ||
| 104 | }  | 
            ||
| 105 | |||
| 106 | $username = $service->getUsernameByEmail($login);  | 
            ||
| 107 | |||
| 108 | // No user found with this email.  | 
            ||
| 109 | View Code Duplication |             if (!$username) { | 
            |
| 110 |                 if (Config::inst()->get(self::class, 'fallback_authenticator') === 'yes') { | 
            ||
| 111 |                     if ($fallbackMember = $this->fallbackAuthenticate($data, $request)) { | 
            ||
| 112 |                         { | 
            ||
| 113 | return $fallbackMember;  | 
            ||
| 114 | }  | 
            ||
| 115 | }  | 
            ||
| 116 | }  | 
            ||
| 117 | |||
| 118 |                 $result->addError(_t('LDAPAuthenticator.INVALIDCREDENTIALS', 'Invalid credentials')); | 
            ||
| 119 | return null;  | 
            ||
| 120 | }  | 
            ||
| 121 |         } else { | 
            ||
| 122 | $username = $login;  | 
            ||
| 123 | }  | 
            ||
| 124 | $serviceAuthenticationResult = $service->authenticate($username, $data['Password']);  | 
            ||
| 125 | $success = $serviceAuthenticationResult['success'] === true;  | 
            ||
| 126 | View Code Duplication |         if (!$success) { | 
            |
| 127 |             if (Config::inst()->get(self::class, 'fallback_authenticator') === 'yes') { | 
            ||
| 128 | $fallbackMember = $this->fallbackAuthenticate($data, $request);  | 
            ||
| 129 |                 if ($fallbackMember) { | 
            ||
| 130 | return $fallbackMember;  | 
            ||
| 131 | }  | 
            ||
| 132 | }  | 
            ||
| 133 | |||
| 134 | $result->addError($serviceAuthenticationResult['message']);  | 
            ||
| 135 | |||
| 136 | return null;  | 
            ||
| 137 | }  | 
            ||
| 138 | |||
| 139 | $data = $service->getUserByUsername($serviceAuthenticationResult['identity']);  | 
            ||
| 140 |         if (!$data) { | 
            ||
| 141 | $result->addError(  | 
            ||
| 142 | _t(  | 
            ||
| 143 | 'LDAPAuthenticator.PROBLEMFINDINGDATA',  | 
            ||
| 144 | 'There was a problem retrieving your user data'  | 
            ||
| 145 | )  | 
            ||
| 146 | );  | 
            ||
| 147 | return null;  | 
            ||
| 148 | }  | 
            ||
| 149 | |||
| 150 | // LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields  | 
            ||
| 151 |         $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first(); | 
            ||
| 152 | View Code Duplication |         if (!($member && $member->exists())) { | 
            |
| 153 | $member = new Member();  | 
            ||
| 154 | $member->GUID = $data['objectguid'];  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | // Update the users from LDAP so we are sure that the email is correct.  | 
            ||
| 158 | // This will also write the Member record.  | 
            ||
| 159 | $service->updateMemberFromLDAP($member);  | 
            ||
| 160 | |||
| 161 |         $request->getSession()->clear('BackURL'); | 
            ||
| 162 | |||
| 163 | return $member;  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 209 | 
This check marks private properties in classes that are never used. Those properties can be removed.