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 ( a58b9e...c0537b )
by Cees-Jan
18s
created

Repository::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Travis\Resource\Async;
4
5
use ApiClients\Client\Travis\CommandBus\Command;
6
use ApiClients\Client\Travis\Resource\HookInterface;
7
use ApiClients\Client\Travis\Resource\Repository as BaseRepository;
8
use ApiClients\Foundation\Transport\CommandBus\Command\RequestCommand;
9
use ApiClients\Foundation\Transport\JsonStream;
10
use GuzzleHttp\Psr7\Request;
11
use React\Promise\CancellablePromiseInterface;
12
use React\Promise\PromiseInterface;
13
use Rx\Observable;
14
use Rx\ObservableInterface;
15
use Rx\React\Promise;
16
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
17
use function React\Promise\resolve;
18
19
class Repository extends BaseRepository
20
{
21
    public function builds(): Observable
22
    {
23
        return unwrapObservableFromPromise($this->handleCommand(
24
            new Command\BuildsCommand($this->slug())
25
        ));
26
    }
27
28
    public function jobs(int $buildId): Observable
29
    {
30
        return Promise::toObservable($this->build($buildId))->flatMap(function (Build $build) {
31
            return $build->jobs();
32
        });
33
    }
34
35
    /**
36
     * @param int $id
37
     * @return CancellablePromiseInterface
38
     */
39
    public function build(int $id): CancellablePromiseInterface
40
    {
41
        return $this->handleCommand(new Command\BuildCommand($id));
42
    }
43
44
    /**
45
     * @return ObservableInterface
46
     */
47
    public function commits(): ObservableInterface
48
    {
49
        return unwrapObservableFromPromise($this->handleCommand(
50
            new Command\CommitsCommand($this->slug())
51
        ));
52
    }
53
54
    /**
55
     * @return Observable
56
     */
57
    public function events(): Observable
58
    {
59
        return unwrapObservableFromPromise(
60
            $this->handleCommand(new Command\RepositoryEventsCommand($this->id()))
61
        );
62
    }
63
64
    /**
65
     * @return PromiseInterface
66
     */
67
    public function settings(): PromiseInterface
68
    {
69
        return $this->handleCommand(
70
            new Command\SettingsCommand($this->id())
71
        );
72
    }
73
74
    /**
75
     * @return PromiseInterface
76
     */
77
    public function isActive(): PromiseInterface
78
    {
79
        return Promise::fromObservable(unwrapObservableFromPromise($this->handleCommand(
80
            new Command\HooksCommand()
81
        ))->filter(function (HookInterface $hook) {
82
            return $this->id() === $hook->id();
83
        }))->then(function (HookInterface $hook) {
84
            return resolve($hook->active());
85
        });
86
    }
87
88
    /**
89
     * @return PromiseInterface
90
     */
91
    public function enable(): PromiseInterface
92
    {
93
        return $this->setActiveStatus(true);
94
    }
95
96
    /**
97
     * @return PromiseInterface
98
     */
99
    public function disable(): PromiseInterface
100
    {
101
        return $this->setActiveStatus(false);
102
    }
103
104
    /**
105
     * @param bool $status
106
     * @return PromiseInterface
107
     */
108
    protected function setActiveStatus(bool $status)
109
    {
110
        return $this->handleCommand(new RequestCommand(
111
            new Request(
112
                'PUT',
113
                'hooks/' . $this->id(),
114
                [],
115
                new JsonStream([
116
                    'hook' => [
117
                        'active' => $status,
118
                    ],
119
                ])
120
            )
121
        ))->then(function () {
122
            return $this->refresh();
123
        });
124
    }
125
126
    /**
127
     * @return ObservableInterface
128
     */
129
    public function branches(): ObservableInterface
130
    {
131
        return unwrapObservableFromPromise($this->handleCommand(
132
            new Command\BranchesCommand($this->id())
133
        ));
134
    }
135
136
    /**
137
     * @return ObservableInterface
138
     */
139
    public function vars(): ObservableInterface
140
    {
141
        return unwrapObservableFromPromise($this->handleCommand(
142
            new Command\VarsCommand($this->id())
143
        ));
144
    }
145
146
    /**
147
     * @return ObservableInterface
148
     */
149
    public function caches(): ObservableInterface
150
    {
151
        return unwrapObservableFromPromise($this->handleCommand(
152
            new Command\CachesCommand($this->id())
153
        ));
154
    }
155
156
    /**
157
     * @return PromiseInterface
158
     */
159
    public function key(): PromiseInterface
160
    {
161
        return $this->handleCommand(
162
            new Command\RepositoryKeyCommand($this->slug())
163
        );
164
    }
165
166
    public function refresh(): PromiseInterface
167
    {
168
        return $this->handleCommand(
169
            new Command\RepositoryCommand($this->slug)
170
        );
171
    }
172
}
173