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 |
||
| 20 | class YubikeyAuthenticator extends MemberAuthenticator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var null|Form |
||
| 24 | */ |
||
| 25 | protected static $form; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Validate |
||
| 29 | */ |
||
| 30 | protected static $yubiService; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @inheritdoc |
||
| 34 | * |
||
| 35 | * @param array $data |
||
| 36 | * @param Form|null $form |
||
| 37 | * |
||
| 38 | * @return null|Member |
||
| 39 | */ |
||
| 40 | public static function authenticate($data, Form $form = null) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param Controller $controller |
||
| 72 | * |
||
| 73 | * @return Form |
||
| 74 | */ |
||
| 75 | public static function get_login_form(Controller $controller) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Name of this authenticator |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public static function get_name() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Update the member to forcefully enable YubiAuth |
||
| 92 | * Also, register the Yubikey to the member. |
||
| 93 | * Documentation: |
||
| 94 | * https://developers.yubico.com/yubikey-val/Getting_Started_Writing_Clients.html |
||
| 95 | * |
||
| 96 | * @param Member $member |
||
| 97 | * @param string $yubiString The Identifier String of the Yubikey |
||
| 98 | */ |
||
| 99 | private static function updateMember($member, $yubiString) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param null|ValidationResult $validation |
||
| 115 | */ |
||
| 116 | private static function updateForm($validation = null) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Validate a member plus it's yubikey login. It compares the fingerprintt and after that, tries to validate the Yubikey string |
||
| 132 | * @param array $data |
||
| 133 | * @param Member $member |
||
| 134 | * @return null|Member |
||
| 135 | */ |
||
| 136 | private static function authenticate_yubikey($data, $member) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Check if the yubikey is unique and linked to the member trying to logon |
||
| 163 | * |
||
| 164 | * @param Member $member |
||
| 165 | * @param string $yubiFingerprint |
||
| 166 | * @return boolean |
||
| 167 | */ |
||
| 168 | private static function validateYubikey($member, $yubiFingerprint) |
||
| 190 | |||
| 191 | |||
| 192 | /** |
||
| 193 | * Handle login if the user did not enter a Yubikey string. |
||
| 194 | * Will break out and return NULL if the member should use their Yubikey |
||
| 195 | * |
||
| 196 | * @param Member $member |
||
| 197 | * @return null|Member |
||
| 198 | */ |
||
| 199 | private static function authenticate_noyubikey($member) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Check if a member is allowed to login without a yubikey |
||
| 212 | * |
||
| 213 | * @param Member $member |
||
| 214 | * @return bool|Member |
||
| 215 | */ |
||
| 216 | private static function checkNoYubiLogins($member) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Check if the member is allowed login after so many days of not using a yubikey |
||
| 233 | * |
||
| 234 | * @param Member $member |
||
| 235 | * @return bool|Member |
||
| 236 | */ |
||
| 237 | private static function checkNoYubiDays($member) |
||
| 257 | } |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.