Completed
Push — master ( 648d4c...817611 )
by Alexpts
05:47
created

Generator::generateRandomString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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