GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MiddlewareRunner   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 49
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 10 2
A call() 0 22 3
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Http\Middleware;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use React\Promise\PromiseInterface;
7
use function React\Promise\resolve;
8
9
final class MiddlewareRunner
10
{
11
    /**
12
     * @var MiddlewareRunner
13
     */
14
    private $middleware;
15
16
    /**
17
     * @param callable[] $middleware
18
     */
19 3
    public function __construct(callable ...$middleware)
20
    {
21 3
        $this->middleware = $middleware;
0 ignored issues
show
Documentation Bug introduced by
It seems like $middleware of type array<integer,array<integer,callable>> is incompatible with the declared type object<WyriHaximus\React...eware\MiddlewareRunner> of property $middleware.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22 3
    }
23
24 3
    public function __invoke(ServerRequestInterface $request, $next)
25
    {
26 3
        $response = $this->call($request, 0, $next);
27
28 3
        if ($response instanceof PromiseInterface) {
29
            return $response;
30
        }
31
32 3
        return resolve($response);
33
    }
34
35 3
    private function call(ServerRequestInterface $request, $position, $last)
36
    {
37 3
        if (!isset($this->middleware[$position])) {
38 1
            return $last($request);
39
        }
40
41
        // final request handler will be invoked without a next handler
42 2
        if (!isset($this->middleware[$position + 1])) {
43 2
            $handler = $this->middleware[$position];
44
45 2
            return $handler($request, $last);
46
        }
47
48
        $next = function (ServerRequestInterface $request) use ($position, $last) {
49 1
            return $this->call($request, $position + 1, $last);
50 1
        };
51
52
        // invoke middleware request handler with next handler
53 1
        $handler = $this->middleware[$position];
54
55 1
        return $handler($request, $next);
56
    }
57
}
58