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.
Completed
Push — master ( fd702e...6c799b )
by Cees-Jan
11s
created

Middleware::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Timer\ResponseBody;
4
5
use ApiClients\Foundation\Middleware\Annotation\SecondLast;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use React\Promise\CancellablePromiseInterface;
10
use Throwable;
11
use function React\Promise\resolve;
12
13
final class Middleware implements MiddlewareInterface
14
{
15
    const HEADER = 'X-Middleware-Timer-Response-Body';
16
17
    /**
18
     * @var float[]
19
     */
20
    private $time = [];
21
22
    /**
23
     * Return the processed $request via a fulfilled promise.
24
     * When implementing cache or other feature that returns a response, do it with a rejected promise.
25
     * If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
26
     *
27
     * @param  RequestInterface            $request
28
     * @param  array                       $options
29
     * @return CancellablePromiseInterface
30
     *
31
     * @SecondLast()
32
     */
33 1
    public function pre(
34
        RequestInterface $request,
35
        string $transactionId,
36
        array $options = []
37
    ): CancellablePromiseInterface {
38 1
        $this->time[$transactionId] = microtime(true);
39
40 1
        return resolve($request);
41
    }
42
43
    /**
44
     * Return the processed $response via a promise.
45
     *
46
     * @param  ResponseInterface           $response
47
     * @param  array                       $options
48
     * @return CancellablePromiseInterface
49
     *
50
     * @SecondLast()
51
     */
52 1
    public function post(
53
        ResponseInterface $response,
54
        string $transactionId,
55
        array $options = []
56
    ): CancellablePromiseInterface {
57 1
        $time = microtime(true) - $this->time[$transactionId];
58 1
        unset($this->time[$transactionId]);
59
60 1
        return resolve($response->withAddedHeader(self::HEADER, (string)$time));
61
    }
62
63
    public function error(
64
        Throwable $throwable,
65
        string $transactionId,
66
        array $options = []
67
    ): CancellablePromiseInterface {
68
        unset($this->time[$transactionId]);
69
    }
70
}
71