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.

Client::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 19
ccs 0
cts 16
cp 0
crap 6
rs 9.6333
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\AppVeyor;
4
5
use ApiClients\Client\AppVeyor\Resource\Sync\Project;
6
use ApiClients\Foundation\Factory as FoundationClientFactory;
7
use React\EventLoop\Factory as LoopFactory;
8
use React\EventLoop\LoopInterface;
9
use Rx\React\Promise;
10
use Rx\Scheduler;
11
use function Clue\React\Block\await;
12
13
final class Client implements ClientInterface
14
{
15
    /**
16
     * @var LoopInterface
17
     */
18
    private $loop;
19
20
    /**
21
     * @var AsyncClientInterface
22
     */
23
    private $client;
24
25
    /**
26
     * @param LoopInterface        $loop
27
     * @param AsyncClientInterface $client
28
     */
29
    private function __construct(LoopInterface $loop, AsyncClientInterface $client)
30
    {
31
        $this->loop = $loop;
32
        $this->client = $client;
33
    }
34
35
    /**
36
     * @param  string $token
37
     * @param  array  $options
38
     * @return Client
39
     */
40
    public static function create(
41
        string $token,
42
        array $options = []
43
    ): self {
44
        $loop = LoopFactory::create();
45
        $options = ApiSettings::getOptions($token, $options, 'Sync');
46
        $client = FoundationClientFactory::create($loop, $options);
47
48
        try {
49
            Scheduler::setAsyncFactory(function () use ($loop) {
50
                return new Scheduler\EventLoopScheduler($loop);
0 ignored issues
show
Documentation introduced by
$loop is of type object<React\EventLoop\LoopInterface>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
            });
52
        } catch (\Throwable $t) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
53
        }
54
55
        $asyncClient = AsyncClient::createFromClient($client);
56
57
        return new self($loop, $asyncClient);
58
    }
59
60
    public function projects(): array
61
    {
62
        return await(
63
            Promise::fromObservable(
64
                $this->client->projects()->toArray()
65
            ),
66
            $this->loop
67
        );
68
    }
69
70
    public function project(string $repository): Project
71
    {
72
        return await(
73
            $this->client->project($repository),
74
            $this->loop
75
        );
76
    }
77
}
78