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::pre()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 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