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.

ContentsHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 18
cts 18
cp 1
rs 9.392
c 0
b 0
f 0
cc 3
nc 1
nop 1
crap 3
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\CommandBus\Handler\Repository;
4
5
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand;
6
use ApiClients\Client\Github\Resource\Contents\DirectoryInterface;
7
use ApiClients\Client\Github\Resource\Contents\FileInterface;
8
use ApiClients\Foundation\Hydrator\Hydrator;
9
use ApiClients\Foundation\Transport\Service\RequestService;
10
use function ApiClients\Tools\Rx\observableFromArray;
11
use function React\Promise\resolve;
12
use RingCentral\Psr7\Request;
13
use Rx\React\Promise;
14
15
final class ContentsHandler
16
{
17
    /**
18
     * @var RequestService
19
     */
20
    private $requestService;
21
22
    /**
23
     * @var Hydrator
24
     */
25
    private $hydrator;
26
27
    /**
28
     * ContentsHandler constructor.
29
     * @param RequestService $requestService
30
     * @param Hydrator       $hydrator
31
     */
32 3
    public function __construct(RequestService $requestService, Hydrator $hydrator)
33
    {
34 3
        $this->requestService = $requestService;
35 3
        $this->hydrator = $hydrator;
36 3
    }
37
38 3
    public function handle(ContentsCommand $command)
39
    {
40 3
        $path = \ltrim($command->getPath(), '/');
41 3
        $uri = 'repos/' . $command->getFullname() . '/contents/' . $path;
42
43 3
        return resolve(
44 3
            Promise::toObservable(
45 3
                $this->requestService->request(
46 3
                    new Request('GET', $uri)
47
                )
48 3
            )->flatMap(function ($contents) {
49 3
                $parsedContents = $contents->getBody()->getParsedContents();
50
                if (isset($parsedContents['type'])) {
51 3
                    return observableFromArray([$parsedContents]);
52 3
                }
53 3
54 3
                return observableFromArray($contents->getBody()->getParsedContents());
55 3
            })->map(function ($content) use ($command) {
56
                $content['repository_fullname'] = $command->getFullname();
57
                if ($content['type'] === 'file') {
58
                    return $this->hydrator->hydrate(
59 3
                        FileInterface::HYDRATE_CLASS,
60 3
                        $content
61 3
                    );
62
                }
63 3
64
                return $this->hydrator->hydrate(
65
                    DirectoryInterface::HYDRATE_CLASS,
66
                    $content
67
                );
68
            })
69
        );
70
    }
71
}
72