| Conditions | 5 |
| Paths | 6 |
| Total Lines | 29 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 5 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 34 | 4 | public function generate($intention = 'm@J0raOaUth') |
|
| 35 | { |
||
| 36 | 4 | $bytes = false; |
|
| 37 | 4 | if (function_exists('openssl_random_pseudo_bytes') && 0 !== stripos(PHP_OS, 'win')) { |
|
| 38 | 4 | $bytes = openssl_random_pseudo_bytes(32, $strong); |
|
| 39 | |||
| 40 | 4 | if (true !== $strong) { |
|
| 41 | 2 | $bytes = false; |
|
| 42 | 1 | } |
|
| 43 | 2 | } |
|
| 44 | |||
| 45 | // let's just hope we got a good seed |
||
| 46 | 4 | if (false === $bytes) { |
|
| 47 | 2 | $bytes = hash('sha512', |
|
| 48 | 2 | sprintf('-[%s}\%s/{%s]-', |
|
| 49 | 1 | $intention, |
|
| 50 | 2 | uniqid(mt_rand(), true), |
|
| 51 | 2 | $this->secret |
|
| 52 | 1 | ), |
|
| 53 | 1 | true |
|
| 54 | 1 | ); |
|
| 55 | 1 | } |
|
| 56 | |||
| 57 | 4 | return str_pad( |
|
| 58 | 4 | base_convert(bin2hex($bytes), 16, 36), |
|
| 59 | 4 | 50, |
|
| 60 | 4 | rand(0, 9) |
|
| 61 | 2 | ); |
|
| 62 | } |
||
| 63 | } |
||
| 64 |