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

src/Server/Logger/ConnectionLogger.php (2 issues)

Labels
Severity

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\Server\Logger;
4
5
use Ratchet\ConnectionInterface;
6
7
class ConnectionLogger extends Logger implements ConnectionInterface
8
{
9
    /** @var \Ratchet\ConnectionInterface */
10
    protected $connection;
11
12
    public static function decorate(ConnectionInterface $app): self
13
    {
14
        $logger = app(self::class);
15
16
        return $logger->setConnection($app);
17
    }
18
19
    public function setConnection(ConnectionInterface $connection)
20
    {
21
        $this->connection = $connection;
22
23
        return $this;
24
    }
25
26
    protected function getConnection()
27
    {
28
        return $this->connection;
29
    }
30
31
    public function send($data)
32
    {
33
        $socketId = $this->connection->socketId ?? null;
0 ignored issues
show
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
34
35
        $this->info("Connection id {$socketId} sending message {$data}");
36
37
        $this->connection->send($data);
38
    }
39
40
    public function close()
41
    {
42
        $this->warn("Connection id {$this->connection->socketId} closing.");
0 ignored issues
show
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
43
44
        $this->connection->close();
45
    }
46
47
    public function __set($name, $value)
48
    {
49
        return $this->connection->$name = $value;
50
    }
51
52
    public function __get($name)
53
    {
54
        return $this->connection->$name;
55
    }
56
57
    public function __isset($name)
58
    {
59
        return isset($this->connection->$name);
60
    }
61
62
    public function __unset($name)
63
    {
64
        unset($this->connection->$name);
65
    }
66
}
67