| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 18 | 
| Code Lines | 7 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 4 | function generateRandomString($length = 10)  | 
            ||
| 5 | { | 
            ||
| 6 | // Check if the length is valid  | 
            ||
| 7 |     if ($length <= 0) { | 
            ||
| 8 | return false;  | 
            ||
| 9 | }  | 
            ||
| 10 | |||
| 11 | // Generate random bytes and convert to a string  | 
            ||
| 12 | $randomBytes = random_bytes($length);  | 
            ||
| 13 | $randomString = base64_encode($randomBytes);  | 
            ||
| 14 | |||
| 15 | // Remove any non-alphanumeric characters  | 
            ||
| 16 |     $randomString = preg_replace('/[^a-zA-Z0-9]/', '', $randomString); | 
            ||
| 17 | |||
| 18 | // Truncate or pad the string to the desired length  | 
            ||
| 19 | $randomString = substr($randomString, 0, $length);  | 
            ||
| 20 | |||
| 21 | return $randomString;  | 
            ||
| 22 | }  |