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
Pull Request — master (#33)
by Cees-Jan
13:22 queued 11:17
created

Client::accounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis;
5
6
use React\EventLoop\Factory as LoopFactory;
7
use Rx\React\Promise;
8
use WyriHaximus\Travis\Resource\RepositoryInterface;
9
use WyriHaximus\Travis\Resource\Sync\Repository;
10
use WyriHaximus\ApiClient\Transport\Client as Transport;
11
use WyriHaximus\ApiClient\Transport\Factory;
12
use function Clue\React\Block\await;
13
use function React\Promise\resolve;
14
15
class Client
16
{
17
    protected $transport;
18
    protected $client;
19
20
    public function __construct(string $token = '', Transport $transport = null)
21
    {
22
        $loop = LoopFactory::create();
23 View Code Duplication
        if (!($transport instanceof Transport)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
            $options = [
25
                    'resource_namespace' => 'Async',
26
                ] + ApiSettings::TRANSPORT_OPTIONS;
27
28
            if ($token !== '') {
29
                $options['headers']['Authorization'] = 'token ' . $token;
30
            }
31
32
            $transport = Factory::create($loop, $options);
33
        }
34
        $this->transport = $transport;
35
        $this->client = new AsyncClient($loop, $token, $this->transport);
36
    }
37
38
    public function repository(string $repository): RepositoryInterface
39
    {
40
        return await(
41
            $this->client->repository($repository),
42
            $this->transport->getLoop()
43
        );
44
    }
45
46
    public function accounts(): array
47
    {
48
        return await(
49
            Promise::fromObservable(
50
                $this->client->accounts()->toArray()
51
            ),
52
            $this->transport->getLoop()
53
        );
54
    }
55
56
    public function broadcasts(): array
57
    {
58
        return await(
59
            Promise::fromObservable(
60
                $this->client->broadcasts()->toArray()
61
            ),
62
            $this->transport->getLoop()
63
        );
64
    }
65
}
66