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.

Middleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 58
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pre() 0 9 1
A post() 0 10 1
A error() 0 7 1
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