Passed
Pull Request — master (#1473)
by
unknown
35:03
created

TokenRevocationHandler::respondToRequest()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
nc 4
nop 2
dl 0
loc 18
rs 9.5555
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\OAuth2\Server\Handlers;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class TokenRevocationHandler extends AbstractTokenHandler
11
{
12
    public function respondToRequest(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
13
    {
14
        $client = $this->validateClient($request);
15
        [$tokenType, $token] = $this->validateToken($request, $client);
16
17
        if ($tokenType !== null && $token !== null) {
18
            if ($tokenType === 'refresh_token') {
19
                $this->refreshTokenRepository->revokeRefreshToken($token['refresh_token_id']);
20
                $this->accessTokenRepository->revokeAccessToken($token['access_token_id']);
21
            } elseif ($tokenType === 'access_token') {
22
                $this->accessTokenRepository->revokeAccessToken($token['jti']);
23
            }
24
        }
25
26
        return $response
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->withSt...e-control', 'no-store') returns the type Psr\Http\Message\MessageInterface which includes types incompatible with the type-hinted return Psr\Http\Message\ResponseInterface.
Loading history...
27
            ->withStatus(200)
28
            ->withHeader('pragma', 'no-cache')
29
            ->withHeader('cache-control', 'no-store');
30
    }
31
}
32