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 |
||
| 13 | View Code Duplication | class JoomlaPassword implements IPassword { |
|
| 14 | |||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | 3 | public function hash($password) { |
|
| 22 | |||
| 23 | /** |
||
| 24 | * Hashes a password with a given salt. |
||
| 25 | * |
||
| 26 | * @param string $password The password to hash. |
||
| 27 | * @param string $salt The password salt. |
||
| 28 | * @return string Returns the password hash. |
||
| 29 | */ |
||
| 30 | 4 | protected function hashRaw($password, $salt) { |
|
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritdoc} |
||
| 38 | */ |
||
| 39 | 1 | public function needsRehash($hash) { |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 3 | public function verify($password, $hash) { |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Split the hash into its calculated hash and salt. |
||
| 54 | * |
||
| 55 | * @param string $hash The hash to split. |
||
| 56 | * @return array An array in the form [$hash, $salt]. |
||
| 57 | */ |
||
| 58 | 3 | protected function splitHash($hash) { |
|
| 66 | } |
||
| 67 |