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 |
||
| 15 | class ThreemaGateway_Tfa_Conventional extends ThreemaGateway_Tfa_AbstractProvider |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Return a description of the 2FA methode. |
||
| 19 | */ |
||
| 20 | public function getDescription() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Called when verifying displaying the choose 2FA mode. |
||
| 35 | * |
||
| 36 | * @return bool |
||
| 37 | */ |
||
| 38 | public function canEnable() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Called when trying to verify user. Sends Threema message. |
||
| 63 | * |
||
| 64 | * @param string $context |
||
| 65 | * @param array $user |
||
| 66 | * @param string $userIp |
||
| 67 | * @param array $providerData |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function triggerVerification($context, array $user, $userIp, array &$providerData) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Called when trying to verify user. Shows input for the secret and such things. |
||
| 124 | * |
||
| 125 | * @param XenForo_View $view |
||
| 126 | * @param string $context |
||
| 127 | * @param array $user |
||
| 128 | * @param array $providerData |
||
| 129 | * @param array $triggerData |
||
| 130 | * @return string HTML code |
||
| 131 | */ |
||
| 132 | public function renderVerification(XenForo_View $view, $context, array $user, |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Called when trying to verify user. Checks whether a given secret is valid. |
||
| 147 | * |
||
| 148 | * @param string $context |
||
| 149 | * @param array $input |
||
| 150 | * @param array $user |
||
| 151 | * @param array $providerData |
||
| 152 | * |
||
| 153 | * @return bool |
||
| 154 | */ |
||
| 155 | public function verifyFromInput($context, XenForo_Input $input, array $user, array &$providerData) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Verifies the Treema ID formally after it was entered/changed. |
||
| 196 | * |
||
| 197 | * @param XenForo_Input $input |
||
| 198 | * @param array $user |
||
| 199 | * @param array $error |
||
| 200 | * |
||
| 201 | * @return array |
||
| 202 | */ |
||
| 203 | public function verifySetupFromInput(XenForo_Input $input, array $user, &$error) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Called before the setup verification is shown. |
||
| 222 | * |
||
| 223 | * @param array $providerData |
||
| 224 | * @param array $triggerData |
||
| 225 | * |
||
| 226 | * @return bool |
||
| 227 | */ |
||
| 228 | protected function initiateSetupData(array &$providerData, array &$triggerData) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Generates the default provider options at setup time before it is |
||
| 235 | * displayed to the user. |
||
| 236 | * |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | protected function generateDefaultData() |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Adjust the view aparams, e.g. add special params needed by your |
||
| 249 | * template. |
||
| 250 | * |
||
| 251 | * @param array $viewParams |
||
| 252 | * @param string $context |
||
| 253 | * @param array $user |
||
| 254 | * |
||
| 255 | * @return array |
||
| 256 | */ |
||
| 257 | protected function adjustViewParams(array $viewParams, $context, array $user) |
||
| 261 | } |
||
| 262 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.