Failed Conditions
Pull Request — master (#125)
by Florent
21:10
created

OAuth2MessageMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Core\Middleware;
15
16
use Psr\Http\Server\RequestHandlerInterface;
17
use Psr\Http\Server\MiddlewareInterface;
18
use OAuth2Framework\Component\Core\Message\OAuth2Message;
19
use OAuth2Framework\Component\Core\Message\OAuth2MessageFactoryManager;
20
use Psr\Http\Message\ResponseInterface;
21
use Psr\Http\Message\ServerRequestInterface;
22
23
final class OAuth2MessageMiddleware implements MiddlewareInterface
24
{
25
    /**
26
     * @var OAuth2MessageFactoryManager
27
     */
28
    private $auth2messageFactoryManager;
29
30
    /**
31
     * OAuth2ResponseMiddleware constructor.
32
     *
33
     * @param OAuth2MessageFactoryManager $auth2messageFactoryManager
34
     */
35
    public function __construct(OAuth2MessageFactoryManager $auth2messageFactoryManager)
36
    {
37
        $this->auth2messageFactoryManager = $auth2messageFactoryManager;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
44
    {
45
        try {
46
            return $handler->handle($request);
47
        } catch (OAuth2Message $e) {
48
            return $oauth2Response = $this->auth2messageFactoryManager->getResponse($e);
0 ignored issues
show
Unused Code introduced by
$oauth2Response 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...
49
        }
50
    }
51
}
52