1 | <?php |
||
32 | class WebSocketServer |
||
33 | { |
||
34 | /** |
||
35 | * @var int |
||
36 | */ |
||
37 | private $port; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $host; |
||
43 | |||
44 | /** |
||
45 | * @var ServerHandshake |
||
46 | */ |
||
47 | private $handshake; |
||
48 | |||
49 | /** |
||
50 | * @var MessageHandlerInterface[] |
||
51 | */ |
||
52 | private $messageHandlers; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | private $connections; |
||
58 | |||
59 | /** |
||
60 | * @var LoopInterface |
||
61 | */ |
||
62 | private $loop; |
||
63 | |||
64 | /** |
||
65 | * @var ServerInterface |
||
66 | */ |
||
67 | private $server; |
||
68 | |||
69 | /** |
||
70 | * @var MessageProcessor |
||
71 | */ |
||
72 | private $messageProcessor; |
||
73 | |||
74 | /** |
||
75 | * @var array |
||
76 | */ |
||
77 | private $config; |
||
78 | |||
79 | /** |
||
80 | * @var LoggerInterface |
||
81 | */ |
||
82 | private $logger; |
||
83 | |||
84 | /** |
||
85 | * @param int $port The number of the port to bind |
||
86 | * @param string $host The host to listen on (by default 127.0.0.1) |
||
87 | * @param array $config |
||
88 | */ |
||
89 | 7 | public function __construct($port, $host = '127.0.0.1', $config = []) |
|
102 | |||
103 | /** |
||
104 | * @param MessageHandlerInterface|string $messageHandler An instance of a class as string |
||
105 | * @param string $uri The URI you want to bind on |
||
106 | */ |
||
107 | 3 | public function setMessageHandler($messageHandler, $uri = '*') |
|
124 | |||
125 | /** |
||
126 | * Launch the WebSocket server and an infinite loop that act on event. |
||
127 | * |
||
128 | * @throws \Exception |
||
129 | */ |
||
130 | 3 | public function start() |
|
156 | |||
157 | /** |
||
158 | * @param ConnectionInterface $socketStream |
||
159 | */ |
||
160 | private function onNewConnection(ConnectionInterface $socketStream) |
||
169 | |||
170 | /** |
||
171 | * @param string $uri |
||
172 | * @param Connection $connection |
||
173 | * @return MessageHandlerInterface|null |
||
174 | */ |
||
175 | 3 | private function getMessageHandler(string $uri, Connection $connection) |
|
197 | |||
198 | /** |
||
199 | * Build the message processor with configuration |
||
200 | */ |
||
201 | 6 | private function buildMessageProcessor() |
|
218 | |||
219 | /** |
||
220 | * Sets the configuration |
||
221 | * |
||
222 | * @param array $config |
||
223 | * @throws ConfigException |
||
224 | */ |
||
225 | 7 | private function setConfig(array $config) |
|
242 | |||
243 | /** |
||
244 | * @return SimpleLogger|LoggerInterface |
||
245 | */ |
||
246 | 3 | public function getLogger() |
|
254 | |||
255 | /** |
||
256 | * Allows you to set a custom logger |
||
257 | * |
||
258 | * @param LoggerInterface $logger |
||
259 | * @return WebSocketServer |
||
260 | */ |
||
261 | public function setLogger(LoggerInterface $logger) |
||
267 | |||
268 | /** |
||
269 | * Allows to specify a loop that will be used instead of the reactphp generated loop. |
||
270 | * |
||
271 | * @param LoopInterface $loop |
||
272 | * @return WebSocketServer |
||
273 | */ |
||
274 | 3 | public function setLoop(LoopInterface $loop) |
|
280 | |||
281 | /** |
||
282 | * @param ServerInterface $server |
||
283 | * @return WebSocketServer |
||
284 | */ |
||
285 | 3 | public function setSocketServer(ServerInterface $server) |
|
291 | } |
||
292 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.