Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
TokenGenerator | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
generateToken | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\User\Component; |
25 | |
26 | use RandomLib\Factory; |
27 | use RandomLib\Generator; |
28 | |
29 | class TokenGenerator |
30 | { |
31 | public const TOKEN_LENGTH = 50; |
32 | /** |
33 | * @var Factory |
34 | */ |
35 | private $factory; |
36 | |
37 | public function __construct(Factory $factory) |
38 | { |
39 | $this->factory = $factory; |
40 | } |
41 | |
42 | /** |
43 | * @return string |
44 | */ |
45 | public function generateToken() |
46 | { |
47 | return $this->factory |
48 | ->getMediumStrengthGenerator() |
49 | ->generateString( |
50 | self::TOKEN_LENGTH, |
51 | Generator::CHAR_DIGITS + Generator::CHAR_LOWER + Generator::CHAR_UPPER |
52 | ); |
53 | } |
54 | } |