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   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 48
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B handle() 0 24 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