Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | final class Dispensary |
||
12 | { |
||
13 | private Repository $repository; |
||
14 | |||
15 | private Hasher $hasher; |
||
16 | |||
17 | public function __construct(Repository $repository, Hasher $hasher) |
||
18 | 17 | { |
|
19 | $this->repository = $repository; |
||
20 | 17 | $this->hasher = $hasher; |
|
21 | 17 | } |
|
22 | 17 | ||
23 | public function dispense(string $key, int $ttl, int $chars): string |
||
30 | 9 | } |
|
31 | |||
32 | /** |
||
33 | * @param string $key |
||
34 | * @param string $token |
||
35 | * @return bool |
||
36 | * @throws \App\Auth\Dispensary\Exceptions\TokenExpiredException |
||
37 | */ |
||
38 | public function verify(string $key, string $token): bool |
||
39 | { |
||
40 | 7 | $hashedToken = $this->repository->get($key); |
|
41 | |||
42 | 7 | if (null === $hashedToken) { |
|
43 | throw new TokenExpiredException(); |
||
44 | 7 | } |
|
45 | 2 | ||
46 | return $this->hasher->check($token, $hashedToken); |
||
47 | } |
||
48 | 5 | ||
49 | private function generateToken(int $chars): string |
||
52 | } |
||
53 | } |
||
54 |