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.

BufferedSinkMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A post() 0 21 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation\Transport\Middleware;
4
5
use ApiClients\Foundation\Middleware\ErrorTrait;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use ApiClients\Foundation\Middleware\PreTrait;
8
use Psr\Http\Message\ResponseInterface;
9
use React\EventLoop\LoopInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use React\Stream\ReadableStreamInterface;
12
use RingCentral\Psr7\BufferStream;
13
use function React\Promise\resolve;
14
use function React\Promise\Stream\buffer;
15
16
class BufferedSinkMiddleware implements MiddlewareInterface
17
{
18
    use PreTrait;
19
    use ErrorTrait;
20
21
    /**
22
     * @var LoopInterface
23
     */
24
    private $loop;
25
26
    /**
27
     * @param LoopInterface $loop
28
     */
29 2
    public function __construct(LoopInterface $loop)
30
    {
31 2
        $this->loop = $loop;
32 2
    }
33
34
    /**
35
     * @param  ResponseInterface           $response
36
     * @param  array                       $options
37
     * @return CancellablePromiseInterface
38
     */
39 2
    public function post(
40
        ResponseInterface $response,
41
        string $transactionId,
42
        array $options = []
43
    ): CancellablePromiseInterface {
44 2
        if (!($response->getBody() instanceof ReadableStreamInterface)) {
45 1
            return resolve($response);
46
        }
47
48 1
        $body = $response->getBody();
49 1
        $this->loop->futureTick(function () use ($body) {
50 1
            $body->resume();
51 1
        });
52
53 1
        return buffer($response->getBody())->then(function (string $body) use ($response) {
54 1
            $stream = new BufferStream(strlen($body));
55 1
            $stream->write($body);
56
57 1
            return resolve($response->withBody($stream));
58 1
        });
59
    }
60
}
61