| Total Complexity | 13 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class WebSocketClient extends StreamClient implements ReactiveInterface { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var WebSocketServer |
||
| 14 | */ |
||
| 15 | protected $server; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param $resource |
||
| 19 | * @param WebSocketServer $server |
||
| 20 | */ |
||
| 21 | public function __construct ($resource, WebSocketServer $server) { |
||
| 22 | parent::__construct($resource); |
||
| 23 | $this->server = $server; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Removes the client from the server and reactor. |
||
| 28 | */ |
||
| 29 | protected function onClose () { |
||
| 30 | $this->server->remove($this); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $payload |
||
| 35 | */ |
||
| 36 | protected function onData (string $payload): void { |
||
|
|
|||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * WebSockets do not use the out-of-band channel. |
||
| 41 | */ |
||
| 42 | final public function onOutOfBand () { |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * When a browser responds to a ping. |
||
| 47 | */ |
||
| 48 | protected function onPong (): void { |
||
| 49 | // stub |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Reads framed messages. |
||
| 54 | */ |
||
| 55 | public function onReadable (): void { |
||
| 56 | $data = $this->recv(4096); |
||
| 57 | $frame = new WebSocketFrame($data); |
||
| 58 | if ($frame->isText()) { |
||
| 59 | $this->onText($frame->getPayload()); |
||
| 60 | } |
||
| 61 | elseif ($frame->isBinary()) { |
||
| 62 | $this->onData($frame->getPayload()); |
||
| 63 | } |
||
| 64 | elseif ($frame->isPong()) { |
||
| 65 | $this->onPong(); |
||
| 66 | } |
||
| 67 | elseif ($frame->isClose()) { |
||
| 68 | $this->close(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Stub. |
||
| 74 | * |
||
| 75 | * @param string $text |
||
| 76 | */ |
||
| 77 | protected function onText (string $text): void { |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Pings the browser. |
||
| 82 | */ |
||
| 83 | public function ping () { |
||
| 84 | $this->write(WebSocketFrame::pack('', WebSocketFrame::OP_PING)); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function writeText (string $message) { |
||
| 90 | } |
||
| 91 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.