NotifyUsersAboutPoke::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 2
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 5
    public function __construct(PusherManager $pusher, DeviceTransformer $transformer)
30
    {
31 5
        $this->pusher = $pusher;
32 5
        $this->transformer = $transformer;
33 5
    }
34
35
    /**
36
     * Handle the server was poked event.
37
     *
38
     * @param ServerWasPoked $event
39
     *
40
     * @return void
41
     */
42 5
    public function handle(ServerWasPoked $event)
43
    {
44 5
        $channel = config('broadcasting.connections.pusher.channel');
45 5
        $device = $event->getDevice();
46
47 5
        if ($device->isPublic()) {
48 4
            $this->pusher->trigger($channel, 'ServerWasPoked', [
49 4
                '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 5
    }
59
}
60