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::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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