AuthorizationServerMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author      Alex Bilbie <[email protected]>
5
 * @copyright   Copyright (c) Alex Bilbie
6
 * @license     http://mit-license.org/
7
 *
8
 * @link        https://github.com/thephpleague/oauth2-server
9
 */
10
11
declare(strict_types=1);
12
13
namespace League\OAuth2\Server\Middleware;
14
15
use League\OAuth2\Server\AuthorizationServer;
16
use League\OAuth2\Server\Exception\OAuthServerException;
17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
20
class AuthorizationServerMiddleware
21
{
22 2
    public function __construct(private AuthorizationServer $server)
23
    {
24 2
    }
25
26 2
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next): ResponseInterface
27
    {
28
        try {
29 2
            $response = $this->server->respondToAccessTokenRequest($request, $response);
30 1
        } catch (OAuthServerException $exception) {
31 1
            return $exception->generateHttpResponse($response);
32
        }
33
34
        // Pass the request and response on to the next responder in the chain
35 1
        return $next($request, $response);
36
    }
37
}
38