Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4.016 |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
53 | 5 | public function generate() |
|
54 | { |
||
55 | 5 | $bytes = 32; |
|
56 | |||
57 | 5 | if ($this->phpfunc->extension_loaded('openssl')) { |
|
|
|||
58 | 5 | 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 | 1 | if ($this->phpfunc->function_exists('random_bytes')) { |
|
66 | return $this->phpfunc->random_bytes($bytes); |
||
67 | } |
||
68 | |||
69 | $message = "Cannot generate cryptographically secure random values. " |
||
70 | . "Please install extension 'openssl' or 'mcrypt', or use " |
||
71 | 1 | . "another cryptographically secure implementation."; |
|
72 | |||
73 | 1 | throw new Exception($message); |
|
74 | } |
||
75 | } |
||
76 |
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: