1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\AppVeyor; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\ProjectCommand; |
6
|
|
|
use ApiClients\Client\AppVeyor\CommandBus\Command\ProjectsCommand; |
7
|
|
|
use ApiClients\Foundation\ClientInterface; |
8
|
|
|
use ApiClients\Foundation\Factory; |
9
|
|
|
use React\EventLoop\LoopInterface; |
10
|
|
|
use React\Promise\PromiseInterface; |
11
|
|
|
use Rx\Observable; |
12
|
|
|
use Rx\ObservableInterface; |
13
|
|
|
use Rx\React\Promise; |
14
|
|
|
use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
15
|
|
|
use function React\Promise\resolve; |
16
|
|
|
use Rx\Scheduler; |
17
|
|
|
|
18
|
|
|
class AsyncClient |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ClientInterface |
22
|
|
|
*/ |
23
|
|
|
private $client; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param LoopInterface $loop |
27
|
|
|
* @param string $token |
28
|
|
|
* @param array $options |
29
|
|
|
* @return AsyncClient |
30
|
|
|
*/ |
31
|
|
|
public static function create( |
32
|
|
|
LoopInterface $loop, |
33
|
|
|
string $token, |
34
|
|
|
array $options = [] |
35
|
|
|
): self { |
36
|
|
|
$options = ApiSettings::getOptions($token, $options, 'Async'); |
37
|
|
|
$client = Factory::create($loop, $options); |
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
Scheduler::setAsyncFactory(function () use ($loop) { |
41
|
|
|
return new Scheduler\EventLoopScheduler($loop); |
|
|
|
|
42
|
|
|
}); |
43
|
|
|
} catch (\Throwable $t) { |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return new self($client); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @internal |
51
|
|
|
* @param ClientInterface $client |
52
|
|
|
* @return AsyncClient |
53
|
|
|
*/ |
54
|
|
|
public static function createFromClient(ClientInterface $client): self |
55
|
|
|
{ |
56
|
|
|
return new self($client); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param ClientInterface $client |
61
|
|
|
*/ |
62
|
|
|
private function __construct(ClientInterface $client) |
63
|
|
|
{ |
64
|
|
|
$this->client = $client; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function projects(): ObservableInterface |
68
|
|
|
{ |
69
|
|
|
return unwrapObservableFromPromise($this->client->handle(new ProjectsCommand())); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function project(string $repository): PromiseInterface |
73
|
|
|
{ |
74
|
|
|
return $this->client->handle(new ProjectCommand($repository)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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: