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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 25.64 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 70.37%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 20
loc 78
ccs 19
cts 27
cp 0.7037
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A pre() 0 11 1
A post() 10 10 1
A error() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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