ConsoleLogEvent::getChannelParametersClassname()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Events;
4
5
use Illuminate\Broadcasting\InteractsWithSockets;
6
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
7
use Illuminate\Foundation\Events\Dispatchable;
8
use Illuminate\Queue\SerializesModels;
9
use Illuminate\Support\Facades\Auth;
10
use MallardDuck\DynamicEcho\Channels\{
11
    BaseDynamicChannelFormula,
12
    PrivateUserChannelParameters,
13
};
14
use MallardDuck\DynamicEcho\Contracts\{
15
    HasDynamicChannelFormula,
16
    ImplementsDynamicEcho,
17
};
18
19
class ConsoleLogEvent implements ShouldBroadcastNow, ImplementsDynamicEcho, HasDynamicChannelFormula
20
{
21
    use Dispatchable;
22
    use InteractsWithSockets;
23
    use BaseDynamicChannelFormula;
0 ignored issues
show
introduced by
The trait MallardDuck\DynamicEcho\...seDynamicChannelFormula requires some properties which are not provided by App\Events\ConsoleLogEvent: $channelAuthName, $eventChannelIdentifierBindingCallback, $channelType
Loading history...
24
25
    public int $userId;
26
27
    /**
28
     * A message text string for the console log notification.
29
     *
30
     * @var string
31
     */
32
    public string $message;
33
34
    public function __construct(string $message)
35
    {
36
        /** @var App\Models\User $user */
37
        $user = Auth::user();
38
        $this->userId = $user->id;
39
        $this->message = $message;
40
    }
41
42
    public static function getChannelParametersClassname(): string
43
    {
44
        return PrivateUserChannelParameters::class;
45
    }
46
47
    /**
48
     * Get the JS callback for this event.
49
     *
50
     * In this case, we're just shoving a message into console.log.
51
     *
52
     * @return string
53
     */
54
    public static function getEventJSCallback(): string
55
    {
56
        return <<<JSCALLBACK
57
(e) => {
58
    console.log(e.message);
59
}
60
JSCALLBACK;
61
    }
62
}
63