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