1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\AppVeyor; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\AddProjectCommand; |
6
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\ProjectCommand; |
7
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\ProjectsCommand; |
8
|
|
|
use ApiClients\Foundation\ClientInterface; |
9
|
|
|
use ApiClients\Foundation\Factory; |
10
|
|
|
use React\EventLoop\LoopInterface; |
11
|
|
|
use React\Promise\PromiseInterface; |
12
|
|
|
use Rx\ObservableInterface; |
13
|
|
|
use Rx\Scheduler; |
14
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
15
|
|
|
|
16
|
|
|
class AsyncClient |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ClientInterface |
20
|
|
|
*/ |
21
|
|
|
private $client; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param ClientInterface $client |
25
|
|
|
*/ |
26
|
|
|
private function __construct(ClientInterface $client) |
27
|
|
|
{ |
28
|
|
|
$this->client = $client; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param LoopInterface $loop |
33
|
|
|
* @param string $token |
34
|
|
|
* @param array $options |
35
|
|
|
* @return AsyncClient |
36
|
|
|
*/ |
37
|
|
|
public static function create( |
38
|
|
|
LoopInterface $loop, |
39
|
|
|
string $token, |
40
|
|
|
array $options = [] |
41
|
|
|
): self { |
42
|
|
|
$options = ApiSettings::getOptions($token, $options, 'Async'); |
43
|
|
|
$client = Factory::create($loop, $options); |
44
|
|
|
|
45
|
|
|
try { |
46
|
|
|
Scheduler::setAsyncFactory(function () use ($loop) { |
47
|
|
|
return new Scheduler\EventLoopScheduler($loop); |
|
|
|
|
48
|
|
|
}); |
49
|
|
|
} catch (\Throwable $t) { |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return new self($client); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @internal |
57
|
|
|
* @param ClientInterface $client |
58
|
|
|
* @return AsyncClient |
59
|
|
|
*/ |
60
|
|
|
public static function createFromClient(ClientInterface $client): self |
61
|
|
|
{ |
62
|
|
|
return new self($client); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function projects(): ObservableInterface |
66
|
|
|
{ |
67
|
|
|
return unwrapObservableFromPromise($this->client->handle(new ProjectsCommand())); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function project(string $repository): PromiseInterface |
71
|
|
|
{ |
72
|
|
|
return $this->client->handle(new ProjectCommand($repository)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function addProject(string $provider, string $repository): PromiseInterface |
76
|
|
|
{ |
77
|
|
|
return $this->client->handle(new AddProjectCommand($provider, $repository)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: