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