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.

RepositoryHandler   A
last analyzed

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
A 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
16
final class RepositoryHandler
17
{
18
    /**
19
     * @var FetchAndHydrateService
20
     */
21
    private $service;
22
23
    /**
24
     * @param FetchAndHydrateService $service
25
     */
26 3
    public function __construct(FetchAndHydrateService $service)
27
    {
28 3
        $this->service = $service;
29 3
    }
30
31
    /**
32
     * Fetch the given repository and hydrate it.
33
     *
34
     * @param  RepositoryCommand $command
35
     * @return PromiseInterface
36
     */
37 3
    public function handle(RepositoryCommand $command): PromiseInterface
38
    {
39 3
        return $this->service->fetch(
40 3
            'repos/' . $command->getRepository(),
41 3
            'repo',
42 3
            RepositoryInterface::HYDRATE_CLASS
43 2
        )->then(function (RepositoryInterface $repository) use ($command) {
44 2
            if ($repository instanceof EmptyResourceInterface) {
45 1
                return reject(RepositoryDoesNotExist::create($command->getRepository()));
46
            }
47
48 1
            return resolve($repository);
49
        }, function (Throwable $throwable) use ($command) {
50 1
            if (!($throwable instanceof ResponseException)) {
51
                return reject($throwable);
52
            }
53
54 1
            if ($throwable->getCode() !== 404) {
55
                return reject($throwable);
56
            }
57
58 1
            return reject(RepositoryDoesNotExist::create($command->getRepository()));
59 3
        });
60
    }
61
}
62