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 |
||
23 | class LDAPAuthenticator extends Authenticator |
||
24 | { |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $name = 'LDAP'; |
||
|
|||
29 | |||
30 | /** |
||
31 | * Set to 'yes' to indicate if this module should look up usernames in LDAP by matching the email addresses. |
||
32 | * |
||
33 | * CAVEAT #1: only set to 'yes' for systems that enforce email uniqueness. |
||
34 | * Otherwise only the first LDAP user with matching email will be accessible. |
||
35 | * |
||
36 | * CAVEAT #2: this is untested for systems that use LDAP with principal style usernames (i.e. [email protected]). |
||
37 | * The system will misunderstand emails for usernames with uncertain outcome. |
||
38 | * |
||
39 | * @var string 'no' or 'yes' |
||
40 | */ |
||
41 | private static $allow_email_login = 'no'; |
||
42 | |||
43 | /** |
||
44 | * Set to 'yes' to fallback login attempts to {@link $fallback_authenticator}. |
||
45 | * This will occur if LDAP fails to authenticate the user. |
||
46 | * |
||
47 | * @var string 'no' or 'yes' |
||
48 | */ |
||
49 | private static $fallback_authenticator = 'no'; |
||
50 | |||
51 | /** |
||
52 | * The class of {@link Authenticator} to use as the fallback authenticator. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private static $fallback_authenticator_class = 'SilverStripe\\Security\\MemberAuthenticator'; |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function get_name() |
||
65 | |||
66 | /** |
||
67 | * @param Controller $controller |
||
68 | * @return LDAPLoginForm |
||
69 | */ |
||
70 | public static function get_login_form(Controller $controller) |
||
74 | |||
75 | /** |
||
76 | * Performs the login, but will also create and sync the Member record on-the-fly, if not found. |
||
77 | * |
||
78 | * @param array $data |
||
79 | * @param Form $form |
||
80 | * @return bool|Member|void |
||
81 | * @throws HTTPResponse_Exception |
||
82 | */ |
||
83 | public static function authenticate($data, Form $form = null) |
||
159 | |||
160 | /** |
||
161 | * Try to authenticate using the fallback authenticator. |
||
162 | * |
||
163 | * @param array $data |
||
164 | * @param null|Form $form |
||
165 | * @return null|Member |
||
166 | */ |
||
167 | protected static function fallback_authenticate($data, Form $form = null) |
||
181 | } |
||
182 |
This check marks private properties in classes that are never used. Those properties can be removed.