Completed
Pull Request — master (#1029)
by Andrew
01:51 queued 36s
created

Psr15AuthorizationServerMiddleware::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 4
cts 5
cp 0.8
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.072
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
namespace League\OAuth2\Server\Middleware;
12
13
use Exception;
14
use League\OAuth2\Server\AuthorizationServer;
15
use League\OAuth2\Server\Exception\OAuthServerException;
16
use Psr\Http\Message\ResponseFactoryInterface;
17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use Psr\Http\Server\MiddlewareInterface;
20
use Psr\Http\Server\RequestHandlerInterface;
21
22
class Psr15AuthorizationServerMiddleware implements MiddlewareInterface
23
{
24
    /**
25
     * @var AuthorizationServer
26
     */
27
    private $server;
28
29
    /**
30
     * @var ResponseFactoryInterface
31
     */
32
    private $responseFactory;
33
34
    /**
35
     * @param AuthorizationServer      $server
36
     * @param ResponseFactoryInterface $responseFactory
37
     */
38 1
    public function __construct(AuthorizationServer $server, ResponseFactoryInterface $responseFactory)
39
    {
40 1
        $this->server = $server;
41 1
        $this->responseFactory = $responseFactory;
42 1
    }
43
44
    /**
45
     * @param ServerRequestInterface  $request
46
     * @param RequestHandlerInterface $handler
47
     *
48
     * @return ResponseInterface
49
     */
50 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
51
    {
52
        try {
53 1
            $response = $this->server->respondToAccessTokenRequest($request, $this->responseFactory->createResponse());
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54 1
        } catch (OAuthServerException $exception) {
55 1
            return $exception->generateHttpResponse($this->responseFactory->createResponse());
56
            // @codeCoverageIgnoreStart
57
        } catch (Exception $exception) {
58
            return (new OAuthServerException($exception->getMessage(), 0, 'unknown_error', 500))
59
                            ->generateHttpResponse($this->responseFactory->createResponse());
60
            // @codeCoverageIgnoreEnd
61
        }
62
63
        // Pass the request on to the next responder in the chain
64
        return $handler->handle($request);
65
    }
66
}
67