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 ( 9f4c19...814630 )
by Cees-Jan
04:35
created

Client   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 0
loc 145
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 1
A __construct() 0 5 1
A repository() 0 7 1
A user() 0 7 1
A sshKey() 0 7 1
A broadcasts() 0 9 1
A repositories() 0 9 1
A createFromClient() 0 4 1
A hooks() 0 9 1
A accounts() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ApiClients\Client\Travis;
5
6
use ApiClients\Foundation\Factory;
7
use React\EventLoop\Factory as LoopFactory;
8
use React\EventLoop\LoopInterface;
9
use Rx\React\Promise;
10
use ApiClients\Client\Travis\Resource\RepositoryInterface;
11
use ApiClients\Client\Travis\Resource\SSHKeyInterface;
12
use ApiClients\Client\Travis\Resource\UserInterface;
13
use function Clue\React\Block\await;
14
use function React\Promise\resolve;
15
16
final class Client implements ClientInterface
17
{
18
    /**
19
     * @var LoopInterface
20
     */
21
    private $loop;
22
23
    /**
24
     * @var AsyncClientInterface
25
     */
26
    private $asyncClient;
27
28
    /**
29
     * Create a new AsyncClient based on the loop and other options pass
30
     *
31
     * @param string $token Instructions to fetch the token: https://blog.travis-ci.com/2013-01-28-token-token-token/
32
     * @param array $options
33
     * @return Client
34
     */
35 1
    public static function create(
36
        string $token = '',
37
        array $options = []
38
    ): self {
39 1
        $loop = LoopFactory::create();
40 1
        $options = ApiSettings::getOptions($token, 'Sync', $options);
41 1
        $client = Factory::create($loop, $options);
42 1
        $asyncClient = AsyncClient::createFromClient($client);
43 1
        return self::createFromClient($loop, $asyncClient);
44
    }
45
46
    /**
47
     * Create an Client from a AsyncClientInterface.
48
     * Be sure to pass in a client with the options from ApiSettings and the Sync namespace suffix,
49
     * and pass in the same loop as associated with the AsyncClient you're passing in.
50
     *
51
     * @param LoopInterface $loop
52
     * @param AsyncClientInterface $asyncClient
53
     * @return Client
54
     */
55 10
    public static function createFromClient(LoopInterface $loop, AsyncClientInterface $asyncClient): self
56
    {
57 10
        return new self($loop, $asyncClient);
58
    }
59
60
    /**
61
     * @param LoopInterface $loop
62
     * @param AsyncClientInterface $asyncClient
63
     */
64 10
    private function __construct(LoopInterface $loop, AsyncClientInterface $asyncClient)
65
    {
66 10
        $this->loop = $loop;
67 10
        $this->asyncClient = $asyncClient;
68 10
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 1
    public function repository(string $repository): RepositoryInterface
74
    {
75 1
        return await(
76 1
            $this->asyncClient->repository($repository),
77 1
            $this->loop
78
        );
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function user(): UserInterface
85
    {
86 1
        return await(
87 1
            $this->asyncClient->user(),
88 1
            $this->loop
89
        );
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 1
    public function sshKey(int $id): SSHKeyInterface
96
    {
97 1
        return await(
98 1
            $this->asyncClient->sshKey($id),
99 1
            $this->loop
100
        );
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 1
    public function hooks(): array
107
    {
108 1
        return await(
109 1
            Promise::fromObservable(
110 1
                $this->asyncClient->hooks()->toArray()
111
            ),
112 1
            $this->loop
113
        );
114
    }
115
116
    /**
117
     * Warning this a intensive operation as it has to make a call for each hook
118
     * to turn it into a Repository!!!
119
     *
120
     * Take a look at examples/repositories-async.php on how to limit the amount of
121
     * concurrent requests.
122
     *
123
     * {@inheritdoc}
124
     */
125 2
    public function repositories(callable $filter = null): array
126
    {
127 2
        return await(
128 2
            Promise::fromObservable(
129 2
                $this->asyncClient->repositories($filter)->toArray()
130
            ),
131 2
            $this->loop
132
        );
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 1
    public function accounts(): array
139
    {
140 1
        return await(
141 1
            Promise::fromObservable(
142 1
                $this->asyncClient->accounts()->toArray()
143
            ),
144 1
            $this->loop
145
        );
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151 1
    public function broadcasts(): array
152
    {
153 1
        return await(
154 1
            Promise::fromObservable(
155 1
                $this->asyncClient->broadcasts()->toArray()
156
            ),
157 1
            $this->loop
158
        );
159
    }
160
}
161