Completed
Push — master ( 53691c...15e6b6 )
by Marcel
01:44
created

src/Statistics/Events/StatisticsUpdated.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Statistics\Events;
4
5
use Illuminate\Queue\SerializesModels;
6
use Illuminate\Broadcasting\PrivateChannel;
7
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
8
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
9
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
10
11
class StatisticsUpdated implements ShouldBroadcast
12
{
13
    use SerializesModels;
14
15
    /** @var \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry */
16
    protected $webSocketsStatisticsEntry;
17
18
    public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry)
19
    {
20
        $this->webSocketsStatisticsEntry = $webSocketsStatisticsEntry;
21
    }
22
23
    public function broadcastWith()
24
    {
25
        return [
26
            'time' => (string) $this->webSocketsStatisticsEntry->created_at,
27
            'app_id' => $this->webSocketsStatisticsEntry->app_id,
28
            'peak_connection_count' => $this->webSocketsStatisticsEntry->peak_connection_count,
0 ignored issues
show
The property peak_connection_count does not seem to exist. Did you mean connection?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
            'websocket_message_count' => $this->webSocketsStatisticsEntry->websocket_message_count,
30
            'api_message_count' => $this->webSocketsStatisticsEntry->api_message_count,
31
        ];
32
    }
33
34
    public function broadcastOn()
35
    {
36
        $channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-');
37
38
        return new PrivateChannel($channelName);
39
    }
40
41
    public function broadcastAs()
42
    {
43
        return 'statistics-updated';
44
    }
45
}
46