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 ( 2b5546...bdc854 )
by Cees-Jan
12s
created

BufferedSinkMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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