| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4 |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 53 | 4 | public function generate() |
|
| 54 | { |
||
| 55 | 4 | $bytes = 32; |
|
| 56 | |||
| 57 | 4 | if ($this->phpfunc->extension_loaded('openssl')) { |
|
|
|
|||
| 58 | 4 | return $this->phpfunc->openssl_random_pseudo_bytes($bytes); |
|
| 59 | } |
||
| 60 | |||
| 61 | 1 | if ($this->phpfunc->extension_loaded('mcrypt')) { |
|
| 62 | 1 | return $this->phpfunc->mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); |
|
| 63 | } |
||
| 64 | |||
| 65 | if ($this->phpfunc->function_exists('random_bytes')) { |
||
| 66 | return $this->phpfunc->random_bytes($bytes); |
||
| 67 | 1 | } |
|
| 68 | |||
| 69 | 1 | $message = "Cannot generate cryptographically secure random values. " |
|
| 70 | . "Please install extension 'openssl' or 'mcrypt', or use " |
||
| 71 | . "another cryptographically secure implementation."; |
||
| 72 | |||
| 73 | throw new Exception($message); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: