Generator::generateRandomString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\Tools;
5
6
use function strlen;
7
8
class Generator
9
{
10
11
    public function generateRandomString(
12
        int $length = 10,
13
        string $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#%^*()-_[]{}<>=/|$'
14
    ): string {
15
        $randomStr = '';
16
        for ($i = 0; $i < $length; $i++) {
17
            $randomCharIndex = random_int(0, strlen($chars) - 1);
18
            $randomStr .= $chars[$randomCharIndex];
19
        }
20
21
        return $randomStr;
22
    }
23
}
24