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 ( 7d689e...de75c1 )
by Cees-Jan
9s
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\Response;
4
5
use ApiClients\Foundation\Middleware\Annotation\First;
6
use ApiClients\Foundation\Middleware\Annotation\Last;
7
use ApiClients\Foundation\Middleware\MiddlewareInterface;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use Throwable;
12
use function React\Promise\resolve;
13
14
final class Middleware implements MiddlewareInterface
15
{
16
    const HEADER = 'X-Middleware-Timer-Response';
17
18
    /**
19
     * @var float[]
20
     */
21
    private $times;
22
23
    /**
24
     * Return the processed $request via a fulfilled promise.
25
     * When implementing cache or other feature that returns a response, do it with a rejected promise.
26
     * If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
27
     *
28
     * @param  RequestInterface            $request
29
     * @param  string                      $transactionId
30
     * @param  array                       $options
31
     * @return CancellablePromiseInterface
32
     *
33
     * @Last()
34
     */
35 1
    public function pre(
36
        RequestInterface $request,
37
        string $transactionId,
38
        array $options = []
39
    ): CancellablePromiseInterface {
40 1
        $this->times[$transactionId] = microtime(true);
41
42 1
        return resolve($request);
43
    }
44
45
    /**
46
     * Return the processed $response via a promise.
47
     *
48
     * @param  ResponseInterface           $response
49
     * @param  string                      $transactionId
50
     * @param  array                       $options
51
     * @return CancellablePromiseInterface
52
     *
53
     * @First()
54
     */
55 1
    public function post(
56
        ResponseInterface $response,
57
        string $transactionId,
58
        array $options = []
59
    ): CancellablePromiseInterface {
60 1
        $time = microtime(true) - $this->times[$transactionId];
61 1
        unset($this->times[$transactionId]);
62
63 1
        return resolve($response->withAddedHeader(self::HEADER, (string)$time));
64
    }
65
66
    /**
67
     * @param  Throwable                   $throwable
68
     * @param  string                      $transactionId
69
     * @param  array                       $options
70
     * @return CancellablePromiseInterface
71
     */
72
    public function error(
73
        Throwable $throwable,
74
        string $transactionId,
75
        array $options = []
76
    ): CancellablePromiseInterface {
77
        unset($this->times[$transactionId]);
78
    }
79
}
80