Completed
Pull Request — master (#32)
by Manuel
03:55
created

NotifyUsersAboutPoke::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.008

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1.008
1
<?php
2
3
namespace PiFinder\Handlers\Events;
4
5
use Vinkla\Pusher\PusherManager;
6
use PiFinder\Events\ServerWasPoked;
7
use PiFinder\Transformers\DeviceTransformer;
8
9
class NotifyUsersAboutPoke
10
{
11
    /**
12
     * The Pusher instance.
13
     *
14
     * @var PusherManager
15
     */
16
    protected $pusher;
17
18
    /**
19
     * @var DeviceTransformer
20
     */
21
    private $transformer;
22
23
    /**
24
     * Create the event handler.
25
     *
26
     * @param PusherManager     $pusher
27
     * @param DeviceTransformer $transformer
28
     */
29 4
    public function __construct(PusherManager $pusher, DeviceTransformer $transformer)
30
    {
31 4
        $this->pusher = $pusher;
32 4
        $this->transformer = $transformer;
33 4
    }
34
35
    /**
36
     * Handle the server was poked event.
37
     *
38
     * @param ServerWasPoked $event
39
     *
40
     * @return void
41
     */
42 4
    public function handle(ServerWasPoked $event)
43
    {
44 4
        $channel = config('broadcasting.connections.pusher.channel');
45 4
        $device = $event->getDevice();
46
47 4
        if ($device->isPublic()) {
48 3
            $this->pusher->trigger($channel, 'ServerWasPoked', [
49 3
                'device' => $this->transformer->transform($device),
50
            ]);
51
        } else {
52 1
            $channel = $channel.'-'.$device->group;
53
54 1
            $this->pusher->trigger($channel, 'ServerWasPoked', [
55 1
                'device' => $this->transformer->transform($device),
56
            ]);
57
        }
58 4
    }
59
}
60