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 66
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 66
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\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 function React\Promise\resolve;
12
use Throwable;
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