WebSocketConnectionProxy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 115
rs 10
wmc 10
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __get() 0 7 2
A __set() 0 4 1
A __isset() 0 4 1
A onFrame() 0 4 1
A __call() 0 5 1
A sendFrame() 0 5 1
A toJson() 0 4 1
A sendFrameReal() 0 5 1
1
<?php
2
namespace PHPDaemon\SockJS;
3
4
/**
5
 * @package    Libraries
6
 * @subpackage SockJS
7
 * @author     Vasily Zorin <[email protected]>
8
 */
9
class WebSocketConnectionProxy implements \PHPDaemon\WebSocket\RouteInterface
10
{
11
    use \PHPDaemon\Traits\StaticObjectWatchdog;
12
13
    protected $realConn;
14
15
    protected $sockjs;
16
17
    /**
18
     * __construct
19
     * @param Application $sockjs
20
     * @param object $conn
21
     */
22
    public function __construct($sockjs, $conn)
23
    {
24
        $this->sockjs = $sockjs;
25
        $this->realConn = $conn;
26
    }
27
28
    /**
29
     * __get
30
     * @param  string $k
31
     * @return mixed
32
     */
33
    public function &__get($k)
34
    {
35
        if (!isset($this->realConn->{$k})) {
36
            return $dummy;
0 ignored issues
show
Bug introduced by
The variable $dummy does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
37
        }
38
        return $this->realConn->{$k};
39
    }
40
41
    /**
42
     * __set
43
     * * @param string $k Key
44
     * * @param mixed $$v Value
0 ignored issues
show
Bug introduced by
There is no parameter named $$v. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @return mixed
46
     */
47
    public function __set($k, $v)
48
    {
49
        return $this->realConn->{$k} = $v;
50
    }
51
52
    /**
53
     * __isset
54
     * @param  string $k
55
     * @return boolean
56
     */
57
    public function __isset($k)
58
    {
59
        return isset($this->realConn->{$k});
60
    }
61
62
63
    /**
64
     * Called when new frame received.
65
     * @param  string $data Frame's data.
66
     * @param  string $type Frame's type ("STRING" OR "BINARY").
67
     * @return boolean      Success.
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
68
     */
69
    public function onFrame($data, $type)
70
    {
71
        $this->realConn->onFrame($data, $type);
72
    }
73
74
    /**
75
     * __call
76
     * @param  string $method
77
     * @param  array $args
78
     * @return mixed
79
     */
80
    public function __call($method, $args)
81
    {
82
        $func = [$this->realConn, $method];
83
        return $func(...$args);
84
    }
85
86
    /**
87
     * Sends a frame.
88
     * @param string $data Frame's data.
89
     * @param integer $type Frame's type. See the constants.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
90
     * @param callback $cb Optional. Callback called when the frame is received by client.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
91
     * @callback $cb ( )
92
     * @return boolean Success.
93
     */
94
    public function sendFrame($data, $type = null, $cb = null)
95
    {
96
        $this->realConn->sendFrame('a' . $this->toJson([$data]), $type, $cb);
0 ignored issues
show
Documentation introduced by
array($data) is of type array<integer,string,{"0":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
        return true;
98
    }
99
100
    /**
101
     * toJson
102
     * @param  string $p
103
     * @return string
104
     */
105
    public function toJson($p)
106
    {
107
        return json_encode($p, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
108
    }
109
110
    /**
111
     * Sends a frame.
112
     * @param  string $data Frame's data.
113
     * @param  integer $type Frame's type. See the constants.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
114
     * @param  callback $cb Optional. Callback called when the frame is received by client.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cb not be callable|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
115
     * @callback $cb ( )
116
     * @return boolean Success.
117
     */
118
    public function sendFrameReal($data, $type = null, $cb = null)
119
    {
120
        $this->realConn->sendFrame($data, $type, $cb);
121
        return true;
122
    }
123
}
124