Total Complexity | 6 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class TokenGenerator implements TokenGeneratorInterface |
||
10 | { |
||
11 | protected int $length; |
||
12 | |||
13 | public function __construct(int $length = 6) |
||
14 | { |
||
15 | $this->length = $length; |
||
16 | 5 | } |
|
17 | |||
18 | 5 | public function getToken(): string |
|
19 | 5 | { |
|
20 | $environmentToken = $this->getDefaultEnvironmentToken(); |
||
21 | 2 | if (!empty($environmentToken)) { |
|
22 | return $environmentToken; |
||
23 | 2 | } |
|
24 | 2 | ||
25 | 1 | $numbers = range(0, 9); |
|
26 | |||
27 | return implode('', array_map(function () use (&$numbers) { |
||
28 | 2 | return array_rand($numbers); |
|
29 | }, range(1, $this->length))); |
||
30 | 2 | } |
|
31 | 2 | ||
32 | 2 | protected function getDefaultEnvironmentToken(): ?string |
|
41 | } |
||
42 | } |
||
43 |