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.

DebugMiddleware::pre()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Debug;
4
5
use ApiClients\Foundation\Middleware\MiddlewareInterface;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use React\EventLoop\LoopInterface;
9
use React\Promise\CancellablePromiseInterface;
10
use React\Stream\WritableResourceStream;
11
use React\Stream\WritableStreamInterface;
12
use Throwable;
13
use function React\Promise\reject;
14
use function React\Promise\resolve;
15
16
final class DebugMiddleware implements MiddlewareInterface
17
{
18
    const HR = '---------------------------------------' . PHP_EOL;
19
20
    /**
21
     * @var WritableStreamInterface
22
     */
23
    private $stdout;
24
25 1
    public function __construct(LoopInterface $loop, WritableStreamInterface $stdout = null)
26
    {
27 1
        if ($stdout === null) {
28
            $stdout = new WritableResourceStream(STDOUT, $loop);
29
        }
30
31 1
        $this->stdout = $stdout;
32 1
    }
33
34
    /**
35
     * Return the processed $request via a fulfilled promise.
36
     * When implementing cache or other feature that returns a response, do it with a rejected promise.
37
     * If neither is possible, e.g. on some kind of failure, resolve the unaltered request.
38
     *
39
     * @param  RequestInterface            $request
40
     * @param  string                      $transactionId
41
     * @param  array                       $options
42
     * @return CancellablePromiseInterface
43
     */
44 1
    public function pre(RequestInterface $request, string $transactionId, array $options = []): CancellablePromiseInterface
45
    {
46 1
        $this->stdout->write(self::HR);
47 1
        $this->stdout->write($transactionId . ': request' . PHP_EOL);
48 1
        $this->stdout->write(self::HR);
49 1
        $this->stdout->write('Method: ' . $request->getMethod() . PHP_EOL);
50 1
        $this->stdout->write('URI: ' . (string)$request->getUri() . PHP_EOL);
51 1
        $this->stdout->write(self::HR);
52
53 1
        return resolve($request);
54
    }
55
56
    /**
57
     * Return the processed $response via a promise.
58
     *
59
     * @param  ResponseInterface           $response
60
     * @param  string                      $transactionId
61
     * @param  array                       $options
62
     * @return CancellablePromiseInterface
63
     */
64 1 View Code Duplication
    public function post(ResponseInterface $response, string $transactionId, array $options = []): CancellablePromiseInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66 1
        $this->stdout->write(self::HR);
67 1
        $this->stdout->write($transactionId . ': response' . PHP_EOL);
68 1
        $this->stdout->write(self::HR);
69 1
        $this->stdout->write('Status: ' . $response->getStatusCode() . PHP_EOL);
70 1
        $this->stdout->write(self::HR);
71
72 1
        return resolve($response);
73
    }
74
75
    /**
76
     * Deal with possible errors that occurred during request/response events.
77
     *
78
     * @param  Throwable                   $throwable
79
     * @param  string                      $transactionId
80
     * @param  array                       $options
81
     * @return CancellablePromiseInterface
82
     */
83 View Code Duplication
    public function error(Throwable $throwable, string $transactionId, array $options = []): CancellablePromiseInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $this->stdout->write(self::HR);
86
        $this->stdout->write($transactionId . ': error' . PHP_EOL);
87
        $this->stdout->write(self::HR);
88
        $this->stdout->write((string)$throwable);
89
        $this->stdout->write(self::HR);
90
91
        return reject($throwable);
92
    }
93
}
94