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 ( 63aea7...119861 )
by Cees-Jan
04:39
created

RepositoryHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 46
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 24 4
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\CommandBus\Handler;
4
5
use ApiClients\Client\Travis\CommandBus\Command\RepositoryCommand;
6
use ApiClients\Client\Travis\Exception\RepositoryDoesNotExist;
7
use ApiClients\Client\Travis\Resource\RepositoryInterface;
8
use ApiClients\Foundation\Resource\EmptyResourceInterface;
9
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
10
use Clue\React\Buzz\Message\ResponseException;
11
use React\Promise\PromiseInterface;
12
use Throwable;
13
use function React\Promise\reject;
14
use function React\Promise\resolve;
15
use function WyriHaximus\React\futureFunctionPromise;
16
17
final class RepositoryHandler
18
{
19
    /**
20
     * @var FetchAndHydrateService
21
     */
22
    private $service;
23
24
    /**
25
     * @param FetchAndHydrateService $service
26
     */
27 3
    public function __construct(FetchAndHydrateService $service)
28
    {
29 3
        $this->service = $service;
30 3
    }
31
32
    /**
33
     * Fetch the given repository and hydrate it
34
     *
35
     * @param RepositoryCommand $command
36
     * @return PromiseInterface
37
     */
38 3
    public function handle(RepositoryCommand $command): PromiseInterface
39
    {
40 3
        return $this->service->fetch(
41 3
            'repos/' . $command->getRepository(),
42 3
            'repo',
43 3
            RepositoryInterface::HYDRATE_CLASS
44
        )->then(function (RepositoryInterface $repository) use ($command) {
45 2
            if ($repository instanceof EmptyResourceInterface) {
46 1
                return reject(RepositoryDoesNotExist::create($command->getRepository()));
47
            }
48
49 1
            return resolve($repository);
50 3
        }, function (Throwable $throwable) use ($command) {
51 1
            if (!($throwable instanceof ResponseException)) {
52
                return reject($throwable);
53
            }
54
55 1
            if ($throwable->getCode() !== 404) {
56
                return reject($throwable);
57
            }
58
59 1
            return reject(RepositoryDoesNotExist::create($command->getRepository()));
60 3
        });
61
    }
62
}
63