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 ( f28526...72a66b )
by Cees-Jan
04:12
created

Middleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 52
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pre() 0 6 1
A post() 0 6 1
A priority() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Timer\ResponseBody;
4
5
use ApiClients\Foundation\Middleware\ErrorTrait;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use ApiClients\Foundation\Middleware\Priority;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use function React\Promise\resolve;
12
13
final class Middleware implements MiddlewareInterface
14
{
15
    use ErrorTrait;
16
17
    const HEADER = 'X-Middleware-Timer-Response-Body';
18
19
    /**
20
     * @var float
21
     */
22
    private $time;
23
24
    /**
25
     * Return the processed $request via a fulfilled promise.
26
     * When implementing cache or other feature that returns a response, do it with a rejected promise.
27
     * If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
28
     *
29
     * @param  RequestInterface            $request
30
     * @param  array                       $options
31
     * @return CancellablePromiseInterface
32
     */
33 1
    public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface
34
    {
35 1
        $this->time = microtime(true);
36
37 1
        return resolve($request);
38
    }
39
40
    /**
41
     * Return the processed $response via a promise.
42
     *
43
     * @param  ResponseInterface           $response
44
     * @param  array                       $options
45
     * @return CancellablePromiseInterface
46
     */
47 1
    public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface
48
    {
49 1
        $time = microtime(true) - $this->time;
50
51 1
        return resolve($response->withAddedHeader(self::HEADER, (string)$time));
52
    }
53
54
    /**
55
     * Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre` and 0 last on `pre`.
56
     * For `post` the order is reversed.
57
     *
58
     * @return int
59
     */
60
    public function priority(): int
61
    {
62
        return Priority::SECOND_LAST;
63
    }
64
}
65