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 ( e716ac...4ea21f )
by Cees-Jan
05:28
created

Client::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 2
crap 6
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github;
4
5
use ApiClients\Client\Github\Resource\UserInterface;
6
use ApiClients\Foundation\Factory as FoundationClientFactory;
7
use React\EventLoop\Factory;
8
use React\EventLoop\LoopInterface;
9
use function Clue\React\Block\await;
10
use Rx\Scheduler;
11
12
final class Client implements ClientInterface
13
{
14
    /**
15
     * @var LoopInterface
16
     */
17
    private $loop;
18
19
    /**
20
     * @var AsyncClient
21
     */
22
    private $client;
23
24
    /**
25
     * @param AuthenticationInterface $auth
26
     * @param array $options
27
     * @return Client
28
     */
29
    public static function create(
30
        AuthenticationInterface $auth,
31
        array $options = []
32
    ): self {
33
        $loop = Factory::create();
34
        $options = ApiSettings::getOptions($auth, $options, 'Sync');
35
        $client = FoundationClientFactory::create($loop, $options);
36
37
        try {
38
            Scheduler::setAsyncFactory(function () use ($loop) {
39
                return new Scheduler\EventLoopScheduler($loop);
40
            });
41
        } catch (\Throwable $t) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
42
        }
43
44
        $asyncClient = AsyncClient::createFromClient($client);
45
46
        return new self($loop, $asyncClient);
47
    }
48
49
    /**
50
     * @param LoopInterface $loop
51
     * @param AsyncClient $client
52
     */
53
    private function __construct(LoopInterface $loop, AsyncClient $client)
54
    {
55
        $this->loop = $loop;
56
        $this->client = $client;
57
    }
58
59
    /**
60
     * @param string $user
61
     * @return UserInterface
62
     */
63
    public function user(string $user): UserInterface
64
    {
65
        return await(
66
            $this->client->user($user),
67
            $this->loop
68
        );
69
    }
70
71
    public function getRateLimitState(): RateLimitState
72
    {
73
        return $this->client->getRateLimitState();
74
    }
75
}
76