Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class ValidationTokenHelper |
||
14 | { |
||
15 | public function __construct( |
||
19 | |||
20 | public function generateLink(int $type, int $resourceId): string |
||
21 | { |
||
22 | $token = new ValidationToken($type, $resourceId); |
||
23 | $this->tokenRepository->save($token, true); |
||
24 | |||
25 | return $this->urlGenerator->generate('validate_token', [ |
||
26 | 'type' => $this->getTypeString($type), |
||
27 | 'hash' => $token->getHash(), |
||
28 | ], UrlGeneratorInterface::ABSOLUTE_URL); |
||
29 | } |
||
30 | |||
31 | public function getTypeId(string $type): int |
||
32 | { |
||
33 | return match ($type) { |
||
34 | 'ticket' => 1, |
||
35 | 'user' => 2, |
||
36 | default => throw new \InvalidArgumentException('Unrecognized validation type'), |
||
37 | }; |
||
38 | } |
||
39 | |||
40 | private function getTypeString(int $type): string |
||
46 | }; |
||
47 | } |
||
48 | } |
||
49 |