Completed
Branch master (bbeaa5)
by Edwin
02:03
created

RedisBroadcaster::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace EdwinLuijten\Ekko\Broadcast\Broadcasters;
4
5
use Predis\ClientInterface;
6
7
class RedisBroadcaster implements BroadcasterInterface
8
{
9
    /**
10
     * @var ClientInterface
11
     */
12
    private $redis;
13
14
    /**
15
     * RedisBroadcaster constructor.
16
     * @param ClientInterface $redis
17
     */
18 6
    public function __construct(ClientInterface $redis)
19
    {
20 6
        $this->redis = $redis;
21 6
    }
22
23
    /**
24
     * Broadcast the given event.
25
     *
26
     * @param  array $channels
27
     * @param  string $event
28
     * @param  array $payload
29
     * @return void
30
     */
31 3
    public function broadcast(array $channels, $event, array $payload = [])
32
    {
33 3
        $payload = json_encode(['event' => $event, 'data' => $payload]);
34
35 3
        foreach ($channels as $channel) {
36 3
            $this->redis->publish($channel, $payload);
37 2
        }
38 3
    }
39
}
40