|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Github\Resource\Async; |
|
4
|
|
|
|
|
5
|
|
|
use ApiClients\Client\Github\CommandBus\Command\IteratePagesCommand; |
|
6
|
|
|
use ApiClients\Client\Github\Resource\Contents\DirectoryInterface; |
|
7
|
|
|
use ApiClients\Client\Github\Resource\Contents\FileInterface; |
|
8
|
|
|
use ApiClients\Client\Github\Resource\Repository as BaseRepository; |
|
9
|
|
|
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand; |
|
10
|
|
|
use ApiClients\Foundation\Transport\CommandBus\Command\JsonEncodeCommand; |
|
11
|
|
|
use ApiClients\Foundation\Transport\CommandBus\Command\RequestCommand; |
|
12
|
|
|
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand; |
|
13
|
|
|
use ApiClients\Foundation\Transport\Response; |
|
14
|
|
|
use GuzzleHttp\Psr7\Request; |
|
15
|
|
|
use React\Promise\PromiseInterface; |
|
16
|
|
|
use Rx\Observable; |
|
17
|
|
|
use Rx\ObservableInterface; |
|
18
|
|
|
use Rx\React\Promise; |
|
19
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
|
20
|
|
|
use function React\Promise\resolve; |
|
21
|
|
|
|
|
22
|
|
|
class Repository extends BaseRepository |
|
23
|
|
|
{ |
|
24
|
|
|
public function refresh() : Repository |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->wait($this->callAsync('refresh')); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function labels(): ObservableInterface |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getCommandBus()->handle( |
|
|
|
|
|
|
32
|
|
|
new IteratePagesCommand('repos/' . $this->fullName() . '/labels') |
|
33
|
|
|
)->flatMap(function ($response) { |
|
34
|
|
|
return Observable::fromArray($response); |
|
35
|
|
|
})->map(function ($label) { |
|
36
|
|
|
return $this->getCommandBus()->handle(new HydrateCommand('Label', $label)); |
|
|
|
|
|
|
37
|
|
|
}); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function addLabel(string $name, string $colour): PromiseInterface |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
return $this->getCommandBus()->handle( |
|
|
|
|
|
|
43
|
|
|
new JsonEncodeCommand([]) |
|
44
|
|
|
)->then(function (string $json) { |
|
45
|
|
|
return $this->getCommandBus()->handle( |
|
|
|
|
|
|
46
|
|
|
new RequestCommand( |
|
47
|
|
|
new Request( |
|
48
|
|
|
'POST', |
|
49
|
|
|
'repos/' . $this->fullName() . '/labels', |
|
50
|
|
|
[], |
|
51
|
|
|
$json |
|
52
|
|
|
) |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
})->then(function (Response $response) { |
|
56
|
|
|
var_export($response->getBody()); |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function contents(): Observable |
|
61
|
|
|
{ |
|
62
|
|
|
return Promise::toObservable($this->handleCommand( |
|
63
|
|
|
new SimpleRequestCommand('repos/' . $this->fullName() . '/contents/') |
|
64
|
|
|
))->flatMap(function ($contents) { |
|
65
|
|
|
return Observable::fromArray($contents->getBody()->getJson()); |
|
66
|
|
|
})->flatMap(function ($content) { |
|
67
|
|
|
if ($content['type'] === 'file') { |
|
68
|
|
|
return Promise::toObservable($this->handleCommand( |
|
69
|
|
|
new HydrateCommand(FileInterface::HYDRATE_CLASS, $content) |
|
70
|
|
|
)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return Promise::toObservable($this->handleCommand( |
|
74
|
|
|
new HydrateCommand(DirectoryInterface::HYDRATE_CLASS, $content) |
|
75
|
|
|
)); |
|
76
|
|
|
}); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.