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