1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Travis\Resource\Sync; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\Travis\Resource\Repository as BaseRepository; |
6
|
|
|
use ApiClients\Client\Travis\Resource\RepositoryInterface; |
7
|
|
|
use ApiClients\Client\Travis\Resource\RepositoryKeyInterface; |
8
|
|
|
use ApiClients\Client\Travis\Resource\SettingsInterface; |
9
|
|
|
use ApiClients\Foundation\Hydrator\CommandBus\Command\BuildAsyncFromSyncCommand; |
10
|
|
|
use Rx\React\Promise; |
11
|
|
|
use function React\Promise\resolve; |
12
|
|
|
|
13
|
|
|
class Repository extends BaseRepository |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
public function builds(): array |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
return $this->wait( |
21
|
|
|
$this->handleCommand( |
22
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
23
|
|
|
)->then(function (RepositoryInterface $repository) { |
24
|
|
|
return Promise::fromObservable($repository->builds()->toArray()); |
|
|
|
|
25
|
|
|
}) |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param int $id |
31
|
|
|
* @return Build |
32
|
|
|
*/ |
33
|
|
|
public function build(int $id): Build |
34
|
|
|
{ |
35
|
|
|
return $this->wait( |
36
|
|
|
$this->handleCommand( |
37
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
38
|
|
|
)->then(function (RepositoryInterface $repository) use ($id) { |
39
|
|
|
return $repository->build($id); |
|
|
|
|
40
|
|
|
}) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function commits(): array |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
return $this->wait( |
50
|
|
|
$this->handleCommand( |
51
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
52
|
|
|
)->then(function (RepositoryInterface $repository) { |
53
|
|
|
return Promise::fromObservable($repository->commits()->toArray()); |
|
|
|
|
54
|
|
|
}) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return SettingsInterface |
60
|
|
|
*/ |
61
|
|
|
public function settings(): SettingsInterface |
62
|
|
|
{ |
63
|
|
|
return $this->wait( |
64
|
|
|
$this->handleCommand( |
65
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
66
|
|
|
)->then(function (RepositoryInterface $repository) { |
67
|
|
|
return $repository->settings(); |
|
|
|
|
68
|
|
|
}) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
public function isActive(): bool |
76
|
|
|
{ |
77
|
|
|
return $this->wait( |
78
|
|
|
$this->handleCommand( |
|
|
|
|
79
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
80
|
|
|
)->then(function (RepositoryInterface $repository) { |
81
|
|
|
return $repository->isActive(); |
|
|
|
|
82
|
|
|
})->otherwise(function (bool $state) { |
83
|
|
|
return resolve($state); |
84
|
|
|
}) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return Repository |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function enable(): Repository |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
return $this->wait( |
94
|
|
|
$this->handleCommand( |
95
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
96
|
|
|
)->then(function (RepositoryInterface $repository) { |
97
|
|
|
return $repository->enable(); |
|
|
|
|
98
|
|
|
}) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return Repository |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function disable(): Repository |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
return $this->wait( |
108
|
|
|
$this->handleCommand( |
109
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
110
|
|
|
)->then(function (RepositoryInterface $repository) { |
111
|
|
|
return $repository->disable(); |
|
|
|
|
112
|
|
|
}) |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
View Code Duplication |
public function branches(): array |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
return $this->wait( |
122
|
|
|
$this->handleCommand( |
123
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
124
|
|
|
)->then(function (RepositoryInterface $repository) { |
125
|
|
|
return Promise::fromObservable($repository->branches()->toArray()); |
|
|
|
|
126
|
|
|
}) |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
View Code Duplication |
public function vars(): array |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
return $this->wait( |
136
|
|
|
$this->handleCommand( |
137
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
138
|
|
|
)->then(function (RepositoryInterface $repository) { |
139
|
|
|
return Promise::fromObservable($repository->vars()->toArray()); |
|
|
|
|
140
|
|
|
}) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
View Code Duplication |
public function caches(): array |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
return $this->wait( |
150
|
|
|
$this->handleCommand( |
151
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
152
|
|
|
)->then(function (RepositoryInterface $repository) { |
153
|
|
|
return Promise::fromObservable($repository->caches()->toArray()); |
|
|
|
|
154
|
|
|
}) |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return RepositoryKeyInterface |
160
|
|
|
*/ |
161
|
|
|
public function key(): RepositoryKeyInterface |
162
|
|
|
{ |
163
|
|
|
return $this->wait( |
164
|
|
|
$this->handleCommand( |
165
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
166
|
|
|
)->then(function (RepositoryInterface $repository) { |
167
|
|
|
return $repository->key(); |
|
|
|
|
168
|
|
|
}) |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return Repository |
174
|
|
|
*/ |
175
|
|
View Code Duplication |
public function refresh(): Repository |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
return $this->wait( |
178
|
|
|
$this->handleCommand( |
179
|
|
|
new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) |
180
|
|
|
)->then(function (RepositoryInterface $repository) { |
181
|
|
|
return $repository->refresh(); |
|
|
|
|
182
|
|
|
}) |
183
|
|
|
); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.