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 Random |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Create a one time token |
||
| 31 | * |
||
| 32 | * Generates a low strength random number of size $bytes and hash with the |
||
| 33 | * algorithm specified in $hash. |
||
| 34 | * |
||
| 35 | * @param string $hash hash function to use |
||
| 36 | * @param integer $bytes the number of random bit to generate |
||
| 37 | * |
||
| 38 | * @return string hashed token |
||
| 39 | */ |
||
| 40 | 9 | View Code Duplication | public static function generateOneTimeToken($hash = 'sha512', $bytes = 64) |
| 47 | |||
| 48 | /** |
||
| 49 | * Create a medium strength key |
||
| 50 | * |
||
| 51 | * Generates a medium strength random number of size $bytes and hash with the |
||
| 52 | * algorithm specified in $hash. |
||
| 53 | * |
||
| 54 | * @param string $hash hash function to use |
||
| 55 | * @param integer $bytes the number of random bytes to generate |
||
| 56 | * |
||
| 57 | * @return string hashed token |
||
| 58 | */ |
||
| 59 | 1 | View Code Duplication | public static function generateKey($hash = 'sha512', $bytes = 128) |
| 66 | } |
||
| 67 |