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 ( a3f15b...1b18fc )
by Cees-Jan
13s
created

Client   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

12 Methods

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