Conditions | 4 |
Paths | 8 |
Total Lines | 25 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
58 | public static function randomString(int $length = 10, bool $includeNumbers = true, bool $includeSymbols = false): string |
||
59 | { |
||
60 | $range = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
||
61 | |||
62 | // Include numbers |
||
63 | if ($includeNumbers) { |
||
64 | $range .= '0123456789'; |
||
65 | } |
||
66 | |||
67 | // Include symbols |
||
68 | if ($includeSymbols) { |
||
69 | $range .= '_!@#$^~'; |
||
70 | } |
||
71 | |||
72 | $finalString = ''; |
||
73 | |||
74 | $srtLen = strlen($range); |
||
75 | |||
76 | for ($i = 0; $i < $length; $i++) { |
||
77 | $randomIndex = rand(0, $srtLen - 1); |
||
78 | |||
79 | $finalString .= $range[$randomIndex]; |
||
80 | } |
||
81 | |||
82 | return $finalString; |
||
83 | } |
||
85 |