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

Generator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateRandomString() 0 12 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