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 ( c17ad1...f97c37 )
by Cees-Jan
07:12
created

RefsHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 13 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\RefsCommand;
6
use ApiClients\Client\Github\Resource\Git\RefInterface;
7
use ApiClients\Client\Github\Service\IteratePagesService;
8
use ApiClients\Foundation\Hydrator\Hydrator;
9
use function ApiClients\Tools\Rx\observableFromArray;
10
use React\Promise\PromiseInterface;
11
use function React\Promise\resolve;
12
13
final class RefsHandler
14
{
15
    /**
16
     * @var IteratePagesService
17
     */
18
    private $iteratePagesService;
19
20
    /**
21
     * @var Hydrator
22
     */
23
    private $hydrator;
24
25
    /**
26
     * @param IteratePagesService $iteratePagesService
27
     * @param Hydrator            $hydrator
28
     */
29
    public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
30
    {
31
        $this->iteratePagesService = $iteratePagesService;
32
        $this->hydrator = $hydrator;
33
    }
34
35
    /**
36
     * @param  RefsCommand      $command
37
     * @return PromiseInterface
38
     */
39
    public function handle(RefsCommand $command): PromiseInterface
40
    {
41
        $namespace = !empty($command->getNamespace()) ? '/' . $command->getNamespace() : '';
42
43
        return resolve(
44
            $this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/git/refs' . $namespace)
45
                ->flatMap(function ($commits) {
46
                    return observableFromArray($commits);
47
                })->map(function ($commit) {
48
                    return $this->hydrator->hydrate(RefInterface::HYDRATE_CLASS, $commit);
49
                })
50
        );
51
    }
52
}
53