GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1f83af...994fb5 )
by Cees-Jan
04:40
created

Client::channel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Pusher;
4
5
use React\EventLoop\Factory;
6
use React\EventLoop\LoopInterface;
7
use React\Promise\Deferred;
8
use Rx\Observer\CallbackObserver;
9
use function Clue\React\Block\await;
10
use function React\Promise\all;
11
12
final class Client
13
{
14
    /**
15
     * @var LoopInterface
16
     */
17
    protected $loop;
18
19
    /**
20
     * @var AsyncClient
21
     */
22
    protected $client;
23
24
    /**
25
     * @param string $app Application ID
26
     */
27
    public function __construct(string $app)
28
    {
29
        $this->loop = Factory::create();
30
        $this->client = new AsyncClient($this->loop, $app);
31
    }
32
33
    /**
34
     * @param string $channel Channel to listen on
35
     * @param callable $listener Listener to call on new messages
36
     */
37
    public function channel(string $channel, callable $listener)
38
    {
39
        $this->channels(
40
            [
41
                $channel,
42
            ],
43
            $listener
44
        );
45
    }
46
47
    /**
48
     * @param string[] $channels Channels to listen on
49
     * @param callable $listener Listener to call on new messages
50
     */
51
    public function channels(array $channels, callable $listener)
52
    {
53
        $promises = [];
54
        foreach ($channels as $channel) {
55
            $deferred = new Deferred();
56
            $this->client->channel($channel)->subscribe(
57
                new CallbackObserver(
58
                    $listener,
59
                    null,
60
                    function () use ($deferred) {
61
                        $deferred->resolve();
62
                    }
63
                )
64
            );
65
            $promises[] = $deferred->promise();
66
        }
67
68
        await(
69
            all($promises),
70
            $this->loop
71
        );
72
    }
73
}
74