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 |
||
| 27 | class PunbbPassword implements IPassword { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | 3 | public function hash($password) { |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Hashes a password with a given salt. |
||
| 39 | * |
||
| 40 | * @param string $password The password to hash. |
||
| 41 | * @param string $salt The password salt. |
||
| 42 | * @return string Returns the password hash. |
||
| 43 | */ |
||
| 44 | 3 | protected function hashRaw($password, $salt) { |
|
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | 1 | View Code Duplication | public function needsRehash($hash) { |
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | 3 | public function verify($password, $hash) { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Split the hash into its calculated hash and salt. |
||
| 85 | * |
||
| 86 | * @param string $hash The hash to split. |
||
| 87 | * @return array An array in the form [$hash, $salt]. |
||
| 88 | */ |
||
| 89 | 4 | protected function splitHash($hash) { |
|
| 97 | } |
||
| 98 |