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

RedisBroadcaster   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A broadcast() 0 8 2
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