for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Helix\Socket;
/**
* Client data framing.
*
* https://tools.ietf.org/html/rfc6455
*/
class WebSocketClient extends StreamClient implements ReactiveInterface {
* @var WebSocketServer
protected $server;
* @param $resource
* @param WebSocketServer $server
public function __construct ($resource, WebSocketServer $server) {
parent::__construct($resource);
$this->server = $server;
}
* Removes the client from the server and reactor.
protected function onClose () {
$this->server->remove($this);
* @param string $payload
protected function onData (string $payload): void {
$payload
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
protected function onData (/** @scrutinizer ignore-unused */ string $payload): void {
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
* WebSockets do not use the out-of-band channel.
final public function onOutOfBand () {
* When a browser responds to a ping.
protected function onPong (): void {
// stub
* Reads framed messages.
public function onReadable (): void {
$data = $this->recv(4096);
$frame = new WebSocketFrame($data);
if ($frame->isText()) {
$this->onText($frame->getPayload());
elseif ($frame->isBinary()) {
$this->onData($frame->getPayload());
elseif ($frame->isPong()) {
$this->onPong();
elseif ($frame->isClose()) {
$this->close();
* Stub.
* @param string $text
protected function onText (string $text): void {
$text
protected function onText (/** @scrutinizer ignore-unused */ string $text): void {
* Pings the browser.
public function ping () {
$this->write(WebSocketFrame::pack('', WebSocketFrame::OP_PING));
public function writeText (string $message) {
$packed = WebSocketFrame::pack($message);
$this->write($packed);
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.