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.

RenderMarkdownHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
ccs 23
cts 23
cp 1
cc 3
nc 1
nop 1
crap 3
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 2
    public function __construct(RequestService $requestService, LoopInterface $loop)
31
    {
32 2
        $this->requestService = $requestService;
33 2
        $this->loop = $loop;
34 2
    }
35
36
    /**
37
     * @param  RenderMarkdownCommand $command
38
     * @return PromiseInterface
39
     */
40 2
    public function handle(RenderMarkdownCommand $command): PromiseInterface
41
    {
42 2
        $stream = new JsonStream();
43
44 2
        $this->loop->futureTick(function () use ($stream, $command) {
45 2
            $markdownStream = new ThroughStream();
46 2
            $stream->write('text', $markdownStream);
47 2
            if ($command->getMode() !== '') {
48 1
                $stream->write('mode', $command->getMode());
49
            }
50 2
            if ($command->getContext() !== '') {
51 1
                $stream->write('context', $command->getContext());
52
            }
53 2
            $stream->end();
54
55 2
            $this->loop->futureTick(function () use ($markdownStream, $command) {
56 2
                $command->getStream()->pipe($markdownStream);
57 2
            });
58 2
        });
59
60 2
        return $this->requestService->request(
61 2
            new Request(
62 2
                'POST',
63 2
                '/markdown',
64 2
                [],
65 2
                new ReadableBodyStream($stream)
66
            )
67 2
        )->then(function ($markdown) {
68 2
            return $markdown->getBody();
69 2
        });
70
    }
71
}
72