| Conditions | 2 |
| Paths | 2 |
| Total Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | 1 | public function encrypt(string $password, string $salt = null, string $algorithm = self::SHA_512): PasswordData |
|
| 10 | { |
||
| 11 | 1 | if (!$salt) { |
|
|
|
|||
| 12 | 1 | $salt = hash($algorithm, uniqid(strval(mt_rand(1, mt_getrandmax())), true)); |
|
| 13 | } |
||
| 14 | |||
| 15 | 1 | $password = hash($algorithm, $password . $salt); |
|
| 16 | |||
| 17 | 1 | return new PasswordData($password, $salt); |
|
| 18 | } |
||
| 19 | |||
| 25 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: