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
Pull Request — master (#24)
by Cees-Jan
09:45
created

RenderMarkdownHandler::handle()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 19
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler;
4
5
use ApiClients\Client\Github\CommandBus\Command\RenderMarkdownCommand;
6
use ApiClients\Foundation\Transport\Service\RequestService;
7
use Clue\React\Buzz\Message\ReadableBodyStream;
8
use React\EventLoop\LoopInterface;
9
use React\Promise\PromiseInterface;
10
use React\Stream\ThroughStream;
11
use RingCentral\Psr7\Request;
12
use WyriHaximus\React\Stream\Json\JsonStream;
13
14
final class RenderMarkdownHandler
15
{
16
    /**
17
     * @var RequestService
18
     */
19
    private $requestService;
20
21
    /**
22
     * @var LoopInterface
23
     */
24
    private $loop;
25
26
    /**
27
     * @param RequestService $requestService
28
     * @param LoopInterface  $loop
29
     */
30
    public function __construct(RequestService $requestService, LoopInterface $loop)
31
    {
32
        $this->requestService = $requestService;
33
        $this->loop = $loop;
34
    }
35
36
    /**
37
     * @param  RenderMarkdownCommand $command
38
     * @return PromiseInterface
39
     */
40
    public function handle(RenderMarkdownCommand $command): PromiseInterface
41
    {
42
        $stream = new JsonStream();
43
44
        $this->loop->futureTick(function () use ($stream, $command) {
45
            $markdownStream = new ThroughStream();
46
            $stream->write('text', $markdownStream);
47
            if ($command->getMode() !== '') {
48
                $stream->write('mode', $command->getMode());
49
            }
50
            if ($command->getContext() !== '') {
51
                $stream->write('context', $command->getContext());
52
            }
53
            $stream->end();
54
55
            $this->loop->futureTick(function () use ($markdownStream, $command) {
56
                $command->getStream()->pipe($markdownStream);
57
            });
58
        });
59
60
        return $this->requestService->request(
61
            new Request(
62
                'POST',
63
                '/markdown',
64
                [],
65
                new ReadableBodyStream($stream)
66
            )
67
        )->then(function ($markdown) {
68
            return $markdown->getBody();
69
        });
70
    }
71
}
72