| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | final class QueryParameter implements AuthenticationMethodInterface |
||
| 17 | { |
||
| 18 | private string $parameterName = 'access-token'; |
||
| 19 | |||
| 20 | private IdentityRepositoryInterface $identityRepository; |
||
| 21 | |||
| 22 | 8 | public function __construct(IdentityRepositoryInterface $identityRepository) |
|
| 23 | { |
||
| 24 | 8 | $this->identityRepository = $identityRepository; |
|
| 25 | 8 | } |
|
| 26 | |||
| 27 | 6 | public function authenticate(ServerRequestInterface $request): ?IdentityInterface |
|
| 28 | { |
||
| 29 | 6 | $accessToken = $request->getQueryParams()[$this->parameterName] ?? null; |
|
| 30 | 6 | if (is_string($accessToken)) { |
|
| 31 | 5 | return $this->identityRepository->findIdentityByToken($accessToken, self::class); |
|
| 32 | } |
||
| 33 | |||
| 34 | 3 | return null; |
|
| 35 | } |
||
| 36 | |||
| 37 | 2 | public function challenge(ResponseInterface $response): ResponseInterface |
|
| 38 | { |
||
| 39 | 2 | return $response; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $name The parameter name for passing the access token. |
||
| 44 | * @return self |
||
| 45 | */ |
||
| 46 | 1 | public function withParameterName(string $name): self |
|
| 51 | } |
||
| 52 | } |
||
| 53 |