1 | <?php |
||
10 | class TokenValidator |
||
11 | { |
||
12 | protected $sign; |
||
13 | protected $base64url; |
||
14 | |||
15 | /** |
||
16 | * Create a new TokenValidator. |
||
17 | * |
||
18 | * @param callable $sign Callable used for generating the token signatures. |
||
19 | */ |
||
20 | public function __construct(callable $sign) |
||
25 | |||
26 | /** |
||
27 | * Determine constraint violations of a CSRF token. |
||
28 | * |
||
29 | * @param string $token The token to validate. |
||
30 | * @param int $now The current time, defaults to `time()`. |
||
31 | * |
||
32 | * @return InvalidArgumentException[] Constraint violations; if $token is valid, an empty array. |
||
33 | */ |
||
34 | public function __invoke($token, $now = null) |
||
46 | |||
47 | /** |
||
48 | * Parse a CSRF token. |
||
49 | * |
||
50 | * @param string $token The token to parse. |
||
51 | * |
||
52 | * @return \stdClass Parse result containing payload and constraint violations. |
||
53 | */ |
||
54 | protected function parse($token) |
||
84 | |||
85 | /** |
||
86 | * Validate the payload of a CSRF token. |
||
87 | * |
||
88 | * @param \stdClass $payload The token payload to validate. |
||
89 | * @param int $now The current time, defaults to `time()`. |
||
90 | * |
||
91 | * @return InvalidArgumentException[] Constraint violations; if $payload is valid, an empty array. |
||
92 | */ |
||
93 | protected function validatePayload(\stdClass $payload, $now = null) |
||
109 | } |
||
110 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.