Completed
Push — master ( edcf20...3ec6c0 )
by Marcel
03:05 queued 01:22
created

Messages/PusherChannelProtocolMessage.php (1 issue)

assigning incompatible types to properties.

Bug Documentation Major

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\WebSockets\Messages;
4
5
use stdClass;
6
use Illuminate\Support\Str;
7
use Ratchet\ConnectionInterface;
8
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
9
10
class PusherChannelProtocolMessage implements PusherMessage
11
{
12
    /** @var \stdClass */
13
    protected $payload;
14
15
    /** @var \React\Socket\ConnectionInterface */
16
    protected $connection;
17
18
    /** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
19
    protected $channelManager;
20
21
    public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager)
22
    {
23
        $this->payload = $payload;
24
25
        $this->connection = $connection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $connection of type object<Ratchet\ConnectionInterface> is incompatible with the declared type object<React\Socket\ConnectionInterface> of property $connection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
27
        $this->channelManager = $channelManager;
28
    }
29
30
    public function respond()
31
    {
32
        $eventName = Str::camel(Str::after($this->payload->event, ':'));
33
34
        if (method_exists($this, $eventName)) {
35
            call_user_func([$this, $eventName], $this->connection, $this->payload->data ?? new stdClass());
36
        }
37
    }
38
39
    /*
40
     * @link https://pusher.com/docs/pusher_protocol#ping-pong
41
     */
42
    protected function ping(ConnectionInterface $connection)
43
    {
44
        $connection->send(json_encode([
45
            'event' => 'pusher:pong',
46
        ]));
47
    }
48
49
    /*
50
     * @link https://pusher.com/docs/pusher_protocol#pusher-subscribe
51
     */
52
    protected function subscribe(ConnectionInterface $connection, stdClass $payload)
53
    {
54
        $channel = $this->channelManager->findOrCreate($connection->app->id, $payload->channel);
55
56
        $channel->subscribe($connection, $payload);
57
    }
58
59
    public function unsubscribe(ConnectionInterface $connection, stdClass $payload)
60
    {
61
        $channel = $this->channelManager->findOrCreate($connection->app->id, $payload->channel);
62
63
        $channel->unsubscribe($connection);
64
    }
65
}
66