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.

Repository::caches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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