Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 28 | class LDAPAuthenticator extends MemberAuthenticator |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $name = 'LDAP'; |
||
|
|
|||
| 34 | |||
| 35 | /** |
||
| 36 | * Set to 'yes' to indicate if this module should look up usernames in LDAP by matching the email addresses. |
||
| 37 | * |
||
| 38 | * CAVEAT #1: only set to 'yes' for systems that enforce email uniqueness. |
||
| 39 | * Otherwise only the first LDAP user with matching email will be accessible. |
||
| 40 | * |
||
| 41 | * CAVEAT #2: this is untested for systems that use LDAP with principal style usernames (i.e. [email protected]). |
||
| 42 | * The system will misunderstand emails for usernames with uncertain outcome. |
||
| 43 | * |
||
| 44 | * @var string 'no' or 'yes' |
||
| 45 | */ |
||
| 46 | private static $allow_email_login = 'no'; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Set to 'yes' to fallback login attempts to {@link $fallback_authenticator}. |
||
| 50 | * This will occur if LDAP fails to authenticate the user. |
||
| 51 | * |
||
| 52 | * @var string 'no' or 'yes' |
||
| 53 | */ |
||
| 54 | private static $fallback_authenticator = 'no'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The class of {@link Authenticator} to use as the fallback authenticator. |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private static $fallback_authenticator_class = MemberAuthenticator::class; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public static function get_name() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param Controller $controller |
||
| 73 | * @return LDAPLoginForm |
||
| 74 | */ |
||
| 75 | public static function get_login_form(Controller $controller) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Performs the login, but will also create and sync the Member record on-the-fly, if not found. |
||
| 82 | * |
||
| 83 | * @param array $data |
||
| 84 | * @param HTTPRequest $request |
||
| 85 | * @param ValidationResult|null $result |
||
| 86 | * @return null|Member |
||
| 87 | */ |
||
| 88 | public function authenticate(array $data, HTTPRequest $request, ValidationResult &$result = null) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Try to authenticate using the fallback authenticator. |
||
| 172 | * |
||
| 173 | * @param array $data |
||
| 174 | * @param HTTPRequest $request |
||
| 175 | * @return null|Member |
||
| 176 | */ |
||
| 177 | protected function fallbackAuthenticate($data, HTTPRequest $request) |
||
| 196 | |||
| 197 | public function getLoginHandler($link) |
||
| 201 | |||
| 202 | public function supportedServices() |
||
| 211 | |||
| 212 | public function getLostPasswordHandler($link) |
||
| 216 | } |
||
| 217 |
This check marks private properties in classes that are never used. Those properties can be removed.