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 ( 0d08ce...5e5f9f )
by Cees-Jan
05:15
created

ContentsHandler::handle()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 15
nc 1
nop 1
crap 2
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 RingCentral\Psr7\Request;
11
use Rx\Observable;
12
use Rx\React\Promise;
13
use function React\Promise\resolve;
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 1
    public function __construct(RequestService $requestService, Hydrator $hydrator)
33
    {
34 1
        $this->requestService = $requestService;
35 1
        $this->hydrator = $hydrator;
36 1
    }
37
38 1
    public function handle(ContentsCommand $command)
39
    {
40 1
        return resolve(
41 1
            Promise::toObservable(
42 1
                $this->requestService->request(
43 1
                    new Request('GET', 'repos/' . $command->getFullname() . '/contents/')
44
                )
45
            )->flatMap(function ($contents) {
46 1
                return Observable::fromArray($contents->getBody()->getJson());
47 1
            })->map(function ($content) {
48 1
                if ($content['type'] === 'file') {
49 1
                    return $this->hydrator->hydrate(
50 1
                        FileInterface::HYDRATE_CLASS,
51
                        $content
52
                    );
53
                }
54
55 1
                return $this->hydrator->hydrate(
56 1
                    DirectoryInterface::HYDRATE_CLASS,
57
                    $content
58
                );
59 1
            })
60
        );
61
    }
62
}
63