| Conditions | 5 |
| Paths | 4 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | private function getRandomNumber() |
||
| 36 | { |
||
| 37 | $nbBytes = 32; |
||
| 38 | |||
| 39 | // try OpenSSL |
||
| 40 | if ($this->useOpenSsl) { |
||
| 41 | $bytes = openssl_random_pseudo_bytes($nbBytes, $strong); |
||
| 42 | |||
| 43 | if (false !== $bytes && true === $strong) { |
||
| 44 | return $bytes; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (null !== $this->logger) { |
||
| 48 | $this->logger->info('OpenSSL did not produce a secure random number.'); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | return hash('sha256', uniqid(mt_rand(), true), true); |
||
| 53 | } |
||
| 54 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: