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 ( e2ac3a...30da43 )
by Cees-Jan
8s
created

AsyncClient::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis;
4
5
use ApiClients\Client\Travis\CommandBus\Command;
6
use ApiClients\Client\Travis\Resource\HookInterface;
7
use ApiClients\Foundation\ClientInterface;
8
use ApiClients\Foundation\Factory;
9
use React\EventLoop\LoopInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use React\Promise\PromiseInterface;
12
use Rx\Observable;
13
use Rx\ObservableInterface;
14
use Rx\React\Promise;
15
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
16
use function React\Promise\resolve;
17
18
final class AsyncClient
19
{
20
    /**
21
     * @var ClientInterface
22
     */
23
    private $client;
24
25
    /**
26
     * @param LoopInterface $loop
27
     * @param string $token
28
     * @param array $options
29
     * @return AsyncClient
30
     */
31
    public static function create(
32
        LoopInterface $loop,
33
        string $token = '',
34
        array $options = []
35
    ): self {
36
        $options = ApiSettings::getOptions($token, 'Async', $options);
37
        $client = Factory::create($loop, $options);
38
        return new self($client);
39
    }
40
41
    /**
42
     * @param ClientInterface $client
43
     * @return AsyncClient
44
     */
45 6
    public static function createFromClient(ClientInterface $client): self
46
    {
47 6
        return new self($client);
48
    }
49
50
    /**
51
     * @param ClientInterface $client
52
     */
53 6
    private function __construct(ClientInterface $client)
54
    {
55 6
        $this->client = $client;
56 6
    }
57
58
    /**
59
     * @param string $repository
60
     * @return CancellablePromiseInterface
61
     */
62 1
    public function repository(string $repository): CancellablePromiseInterface
63
    {
64 1
        return $this->client->handle(new Command\RepositoryCommand($repository));
65
    }
66
67
    /**
68
     * @return ObservableInterface
69
     */
70
    public function repositories(): ObservableInterface
71
    {
72
        return $this->hooks()->filter(function ($hook) {
73
            return $hook->active();
74
        })->flatMap(function (HookInterface $hook) {
75
            return Promise::toObservable($this->client->handle(
76
                new Command\RepositoryIdCommand($hook->id())
77
            ));
78
        });
79
    }
80
81
    /**
82
     * @return PromiseInterface
83
     */
84
    public function user(): PromiseInterface
85
    {
86 1
        return $this->client->handle(new Command\UserCommand());
87
    }
88
89
    /**
90
     * @param int $id
91
     * @return PromiseInterface
92
     */
93 1
    public function sshKey(int $id): PromiseInterface
94
    {
95 1
        return $this->client->handle(new Command\SSHKeyCommand($id));
96
    }
97
98
    /**
99
     * @return ObservableInterface
100
     */
101
    public function hooks(): ObservableInterface
102
    {
103
        return unwrapObservableFromPromise($this->client->handle(
104
            new Command\HooksCommand()
105
        ));
106
    }
107
108
    /**
109
     * @return ObservableInterface
110
     */
111
    public function accounts(): ObservableInterface
112
    {
113
        return unwrapObservableFromPromise($this->client->handle(
114
            new Command\AccountsCommand()
115
        ));
116
    }
117
118
    /**
119
     * @return ObservableInterface
120
     */
121
    public function broadcasts(): ObservableInterface
122
    {
123
        return unwrapObservableFromPromise($this->client->handle(
124
            new Command\BroadcastsCommand()
125
        ));
126
    }
127
}
128