| Conditions | 1 |
| Paths | 1 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | static function generate() { |
||
|
|
|||
| 13 | $uuid = sprintf('%04x%04x%04x%03x4%04x%04x%04x%04x', |
||
| 14 | mt_rand(0, 65535), mt_rand(0, 65535), // 32 bits for "time_low" |
||
| 15 | mt_rand(0, 65535), // 16 bits for "time_mid" |
||
| 16 | mt_rand(0, 4095), // 12 bits before the 0100 of (version) 4 for "time_hi_and_version" |
||
| 17 | bindec(substr_replace(sprintf('%016b', mt_rand(0, 65535)), '01', 6, 2)), |
||
| 18 | // 8 bits, the last two of which (positions 6 and 7) are 01, for "clk_seq_hi_res" |
||
| 19 | // (hence, the 2nd hex digit after the 3rd hyphen can only be 1, 5, 9 or d) |
||
| 20 | // 8 bits for "clk_seq_low" |
||
| 21 | mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535) // 48 bits for "node" |
||
| 22 | ); |
||
| 23 | return $uuid; |
||
| 24 | } |
||
| 25 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.