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 ( 81d6fd...70ec3f )
by Cees-Jan
07:09
created

ContentsHandler::handle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 1
nop 1
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\CommandBus\Command\UserCommand;
7
use ApiClients\Client\Github\Resource\Contents\DirectoryInterface;
8
use ApiClients\Client\Github\Resource\Contents\FileInterface;
9
use ApiClients\Client\Github\Resource\UserInterface;
10
use ApiClients\Foundation\Hydrator\Hydrator;
11
use ApiClients\Foundation\Transport\Service\RequestService;
12
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
13
use React\Promise\PromiseInterface;
14
use function React\Promise\resolve;
15
use RingCentral\Psr7\Request;
16
use Rx\Observable;
17
use Rx\React\Promise;
18
use function WyriHaximus\React\futureFunctionPromise;
19
20
final class ContentsHandler
21
{
22
    /**
23
     * @var RequestService
24
     */
25
    private $requestService;
26
27
    /**
28
     * @var Hydrator
29
     */
30
    private $hydrator;
31
32
    /**
33
     * ContentsHandler constructor.
34
     * @param RequestService $requestService
35
     * @param Hydrator $hydrator
36
     */
37
    public function __construct(RequestService $requestService, Hydrator $hydrator)
38
    {
39
        $this->requestService = $requestService;
40
        $this->hydrator = $hydrator;
41
    }
42
43
    public function handle(ContentsCommand $command)
44
    {
45
        return resolve(Promise::toObservable($this->requestService->handle(
46
            new Request('GET', 'repos/' . $command->getFullname() . '/contents/')
47
        ))->flatMap(function ($contents) {
48
            return Observable::fromArray($contents->getBody()->getJson());
49
        })->map(function ($content) {
50
            if ($content['type'] === 'file') {
51
                return $this->hydrator->hydrate(
52
                    FileInterface::HYDRATE_CLASS,
53
                    $content
54
                );
55
            }
56
57
            return $this->hydrator->hydrate(
58
                DirectoryInterface::HYDRATE_CLASS,
59
                $content
60
            );
61
        }));
62
    }
63
}
64