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 Authenticate |
||
29 | { |
||
30 | /** |
||
31 | * @var string|bool $session_key The session key |
||
32 | */ |
||
33 | private $session_key = false; |
||
34 | |||
35 | /** |
||
36 | * @var object $db The database connection object |
||
37 | */ |
||
38 | public $db; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | * @param object $db_connection The database connection object |
||
43 | * @param string $session_key The session key |
||
44 | */ |
||
45 | View Code Duplication | public function __construct($db_connection=false, $session_key=false) |
|
52 | |||
53 | /** |
||
54 | * Generate Hash |
||
55 | * |
||
56 | * Hash a password using BCrypt as the hashing technique. |
||
57 | * |
||
58 | * @param string $password The data value |
||
59 | * @return string |
||
60 | */ |
||
61 | public function generate_hashed_password($password) |
||
68 | |||
69 | /** |
||
70 | * Verify Hashed Password |
||
71 | * |
||
72 | * Verify a hashed password. |
||
73 | * |
||
74 | * @param string $password The data value |
||
75 | * @param string $hashedPassword The data value |
||
76 | * @return bool |
||
77 | */ |
||
78 | private function verify_hashed_password($password, $hashedPassword) |
||
82 | |||
83 | /** |
||
84 | * Authenticate Local |
||
85 | * |
||
86 | * Run a query to find an active local user account. |
||
87 | * |
||
88 | * @param string $username The data value |
||
89 | * @param string $password The data value |
||
90 | * @return array|bool The query result |
||
91 | */ |
||
92 | public function authenticate_local($username, $password) |
||
116 | |||
117 | /** |
||
118 | * Log Login Attempt |
||
119 | * |
||
120 | * Run a query to insert a login attempt. |
||
121 | * |
||
122 | * @param string $user_account_email The data value |
||
123 | * @param string $result The data value |
||
124 | * @return void |
||
125 | */ |
||
126 | public function log_login_attempt($user_account_email, $result) |
||
148 | } |
||
149 |