diff --git a/composer.json b/composer.json index 3b9ebf1e..3c5462b7 100644 --- a/composer.json +++ b/composer.json @@ -1,40 +1,49 @@ { - "name": "cboden/ratchet" - , "type": "library" - , "description": "PHP WebSocket library" - , "keywords": ["WebSockets", "Server", "Ratchet", "Sockets", "WebSocket"] - , "homepage": "http://socketo.me" - , "license": "MIT" - , "authors": [ + "name": "cboden/ratchet", + "type": "library", + "description": "PHP WebSocket library", + "keywords": [ + "WebSockets", + "Server", + "Ratchet", + "Sockets", + "WebSocket" + ], + "homepage": "http://socketo.me", + "license": "MIT", + "authors": [ { - "name": "Chris Boden" - , "email": "cboden@gmail.com" - , "role": "Developer" - } - , { - "name": "Matt Bonneau" - , "role": "Developer" + "name": "Chris Boden", + "email": "cboden@gmail.com", + "role": "Developer" + }, + { + "name": "Matt Bonneau", + "role": "Developer" } - ] - , "support": { - "issues": "https://github.com/ratchetphp/Ratchet/issues" - , "chat": "https://gitter.im/reactphp/reactphp" - } - , "autoload": { + ], + "support": { + "issues": "https://github.com/ratchetphp/Ratchet/issues", + "chat": "https://gitter.im/reactphp/reactphp" + }, + "autoload": { "psr-4": { "Ratchet\\": "src/Ratchet" } - } - , "require": { - "php": ">=5.4.2" - , "ratchet/rfc6455": "^0.4.0 | ^0.3.1" - , "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5" - , "react/event-loop": "^1.0 || ^0.5 || ^0.4" - , "guzzlehttp/psr7": "^1.7|^2.0" - , "symfony/http-foundation": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0" - , "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0" - } - , "require-dev": { + }, + "require": { + "php": ">=5.4.2", + "ratchet/rfc6455": "^0.4.0 | ^0.3.1", + "react/socket": "^1.0 || ^0.8 || ^0.7 || ^0.6 || ^0.5", + "react/event-loop": "^1.0 || ^0.5 || ^0.4", + "guzzlehttp/psr7": "^1.7|^2.0", + "symfony/http-foundation": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0", + "symfony/routing": "^2.6|^3.0|^4.0|^5.0|^6.0|^7.0" + }, + "require-dev": { "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" + }, + "scripts": { + "tests": "vendor/bin/phpunit" } } diff --git a/src/Ratchet/Server/FlashPolicy.php b/src/Ratchet/Server/FlashPolicy.php index 4a1b8bdf..d38ceea3 100644 --- a/src/Ratchet/Server/FlashPolicy.php +++ b/src/Ratchet/Server/FlashPolicy.php @@ -66,7 +66,7 @@ public function addAllowedAccess($domain, $ports = '*', $secure = false) { throw new \UnexpectedValueException('Invalid Port'); } - $this->_access[] = array($domain, $ports, (boolean)$secure); + $this->_access[] = [$domain, $ports, (bool) $secure]; $this->_cacheValid = false; return $this; diff --git a/src/Ratchet/Wamp/ServerProtocol.php b/src/Ratchet/Wamp/ServerProtocol.php index 2d6d799c..781a5964 100644 --- a/src/Ratchet/Wamp/ServerProtocol.php +++ b/src/Ratchet/Wamp/ServerProtocol.php @@ -72,7 +72,7 @@ public function getSubProtocols() { */ public function onOpen(ConnectionInterface $conn) { $decor = new WampConnection($conn); - $this->connections->attach($conn, $decor); + $this->connections->offsetSet($conn, $decor); $this->_decorating->onOpen($decor); } @@ -125,7 +125,7 @@ public function onMessage(ConnectionInterface $from, $msg) { case static::MSG_PUBLISH: $exclude = (array_key_exists(3, $json) ? $json[3] : null); if (!is_array($exclude)) { - if (true === (boolean)$exclude) { + if (true === (bool)$exclude) { $exclude = [$from->WAMP->sessionId]; } else { $exclude = []; @@ -147,7 +147,7 @@ public function onMessage(ConnectionInterface $from, $msg) { */ public function onClose(ConnectionInterface $conn) { $decor = $this->connections[$conn]; - $this->connections->detach($conn); + $this->connections->offsetUnset($conn); $this->_decorating->onClose($decor); } diff --git a/src/Ratchet/Wamp/Topic.php b/src/Ratchet/Wamp/Topic.php index 675b236e..a1a0580c 100644 --- a/src/Ratchet/Wamp/Topic.php +++ b/src/Ratchet/Wamp/Topic.php @@ -58,7 +58,7 @@ public function broadcast($msg, array $exclude = array(), array $eligible = arra * @return boolean */ public function has(ConnectionInterface $conn) { - return $this->subscribers->contains($conn); + return $this->subscribers->offsetExists($conn); } /** @@ -66,7 +66,7 @@ public function has(ConnectionInterface $conn) { * @return Topic */ public function add(ConnectionInterface $conn) { - $this->subscribers->attach($conn); + $this->subscribers->offsetSet($conn); return $this; } @@ -76,8 +76,8 @@ public function add(ConnectionInterface $conn) { * @return Topic */ public function remove(ConnectionInterface $conn) { - if ($this->subscribers->contains($conn)) { - $this->subscribers->detach($conn); + if ($this->subscribers->offsetExists($conn)) { + $this->subscribers->offsetUnset($conn); } return $this; diff --git a/src/Ratchet/Wamp/TopicManager.php b/src/Ratchet/Wamp/TopicManager.php index dd06ada4..e2b2936c 100644 --- a/src/Ratchet/Wamp/TopicManager.php +++ b/src/Ratchet/Wamp/TopicManager.php @@ -39,12 +39,12 @@ public function onCall(ConnectionInterface $conn, $id, $topic, array $params) { public function onSubscribe(ConnectionInterface $conn, $topic) { $topicObj = $this->getTopic($topic); - if ($conn->WAMP->subscriptions->contains($topicObj)) { + if ($conn->WAMP->subscriptions->offsetExists($topicObj)) { return; } $this->topicLookup[$topic]->add($conn); - $conn->WAMP->subscriptions->attach($topicObj); + $conn->WAMP->subscriptions->offsetSet($topicObj); $this->app->onSubscribe($conn, $topicObj); } @@ -54,7 +54,7 @@ public function onSubscribe(ConnectionInterface $conn, $topic) { public function onUnsubscribe(ConnectionInterface $conn, $topic) { $topicObj = $this->getTopic($topic); - if (!$conn->WAMP->subscriptions->contains($topicObj)) { + if (!$conn->WAMP->subscriptions->offsetExists($topicObj)) { return; } @@ -112,8 +112,8 @@ protected function getTopic($topic) { } protected function cleanTopic(Topic $topic, ConnectionInterface $conn) { - if ($conn->WAMP->subscriptions->contains($topic)) { - $conn->WAMP->subscriptions->detach($topic); + if ($conn->WAMP->subscriptions->offsetExists($topic)) { + $conn->WAMP->subscriptions->offsetUnset($topic); } $this->topicLookup[$topic->getId()]->remove($conn); diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 88c56348..67218fe8 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -150,7 +150,7 @@ function(FrameInterface $frame) use ($wsConn) { $this->ueFlowFactory ); - $this->connections->attach($conn, new ConnContext($wsConn, $streamer)); + $this->connections->offsetSet($conn, new ConnContext($wsConn, $streamer)); return $this->delegate->onOpen($wsConn); } @@ -170,9 +170,9 @@ public function onMessage(ConnectionInterface $from, $msg) { * {@inheritdoc} */ public function onClose(ConnectionInterface $conn) { - if ($this->connections->contains($conn)) { + if ($this->connections->offsetExists($conn)) { $context = $this->connections[$conn]; - $this->connections->detach($conn); + $this->connections->offsetUnset($conn); $this->delegate->onClose($context->connection); } @@ -182,7 +182,7 @@ public function onClose(ConnectionInterface $conn) { * {@inheritdoc} */ public function onError(ConnectionInterface $conn, \Exception $e) { - if ($this->connections->contains($conn)) { + if ($this->connections->offsetExists($conn)) { $this->delegate->onError($this->connections[$conn]->connection, $e); } else { $conn->close(); @@ -215,7 +215,7 @@ public function enableKeepAlive(LoopInterface $loop, $interval = 30) { $this->pongReceiver = function(FrameInterface $frame, $wsConn) use ($pingedConnections, &$lastPing) { if ($frame->getPayload() === $lastPing->getPayload()) { - $pingedConnections->detach($wsConn); + $pingedConnections->offsetUnset($wsConn); } }; @@ -231,7 +231,7 @@ public function enableKeepAlive(LoopInterface $loop, $interval = 30) { $wsConn = $this->connections[$conn]->connection; $wsConn->send($lastPing); - $pingedConnections->attach($wsConn); + $pingedConnections->offsetSet($wsConn); } }); } diff --git a/tests/unit/AbstractConnectionDecoratorTest.php b/tests/unit/AbstractConnectionDecoratorTest.php index 8c5b379c..2ecf10f1 100644 --- a/tests/unit/AbstractConnectionDecoratorTest.php +++ b/tests/unit/AbstractConnectionDecoratorTest.php @@ -90,9 +90,9 @@ public function testUnsetLevel2() { public function testGetConnection() { $class = new \ReflectionClass('Ratchet\\AbstractConnectionDecorator'); $method = $class->getMethod('getConnection'); - $method->setAccessible(true); + // $method->setAccessible(true); - $conn = $method->invokeArgs($this->l1, array()); + $conn = $method->invokeArgs($this->l1, []); $this->assertSame($this->mock, $conn); } @@ -100,9 +100,9 @@ public function testGetConnection() { public function testGetConnectionLevel2() { $class = new \ReflectionClass('Ratchet\\AbstractConnectionDecorator'); $method = $class->getMethod('getConnection'); - $method->setAccessible(true); + // $method->setAccessible(true); - $conn = $method->invokeArgs($this->l2, array()); + $conn = $method->invokeArgs($this->l2, []); $this->assertSame($this->l1, $conn); } diff --git a/tests/unit/AppTest.php b/tests/unit/AppTest.php index b3c879e3..9a4fcbc8 100644 --- a/tests/unit/AppTest.php +++ b/tests/unit/AppTest.php @@ -23,7 +23,7 @@ public function testCtorWithoutArgumentsStartsListeningOnDefaultPorts() { $app = new App(); $ref = new \ReflectionProperty($app, '_server'); - $ref->setAccessible(true); + // $ref->setAccessible(true); $server = $ref->getValue($app); assert($server instanceof IoServer); diff --git a/tests/unit/Wamp/ServerProtocolTest.php b/tests/unit/Wamp/ServerProtocolTest.php index 4e4983fa..a8e9165a 100644 --- a/tests/unit/Wamp/ServerProtocolTest.php +++ b/tests/unit/Wamp/ServerProtocolTest.php @@ -79,7 +79,7 @@ public function testSubscribe() { public function testUnSubscribe() { $uri = 'http://example.com/endpoint'; - $clientMessage = array(6, $uri); + $clientMessage = [6, $uri]; $conn = $this->newConn(); @@ -190,9 +190,9 @@ public function testOnClosePropagation() { $class = new \ReflectionClass('Ratchet\\Wamp\\WampConnection'); $method = $class->getMethod('getConnection'); - $method->setAccessible(true); + // $method->setAccessible(true); - $check = $method->invokeArgs($this->_app->last['onClose'][0], array()); + $check = $method->invokeArgs($this->_app->last['onClose'][0], []); $this->assertSame($conn, $check); } @@ -207,9 +207,9 @@ public function testOnErrorPropagation() { $class = new \ReflectionClass('Ratchet\\Wamp\\WampConnection'); $method = $class->getMethod('getConnection'); - $method->setAccessible(true); + // $method->setAccessible(true); - $check = $method->invokeArgs($this->_app->last['onError'][0], array()); + $check = $method->invokeArgs($this->_app->last['onError'][0], []); $this->assertSame($conn, $check); $this->assertSame($e, $this->_app->last['onError'][1]); diff --git a/tests/unit/Wamp/TopicManagerTest.php b/tests/unit/Wamp/TopicManagerTest.php index fd67fdd5..0036d705 100644 --- a/tests/unit/Wamp/TopicManagerTest.php +++ b/tests/unit/Wamp/TopicManagerTest.php @@ -34,9 +34,9 @@ public function setUpManager() { public function testGetTopicReturnsTopicObject() { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + // $method->setAccessible(true); - $topic = $method->invokeArgs($this->mngr, array('The Topic')); + $topic = $method->invokeArgs($this->mngr, ['The Topic']); $this->assertInstanceOf('Ratchet\Wamp\Topic', $topic); } @@ -46,9 +46,9 @@ public function testGetTopicCreatesTopicWithSameName() { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + //$method->setAccessible(true); - $topic = $method->invokeArgs($this->mngr, array($name)); + $topic = $method->invokeArgs($this->mngr, [$name]); $this->assertEquals($name, $topic->getId()); } @@ -56,10 +56,10 @@ public function testGetTopicCreatesTopicWithSameName() { public function testGetTopicReturnsSameObject() { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + // $method->setAccessible(true); - $topic = $method->invokeArgs($this->mngr, array('No copy')); - $again = $method->invokeArgs($this->mngr, array('No copy')); + $topic = $method->invokeArgs($this->mngr, ['No copy']); + $again = $method->invokeArgs($this->mngr, ['No copy']); $this->assertSame($topic, $again); } @@ -95,13 +95,13 @@ public function testTopicIsInConnectionOnSubscribe() { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + // $method->setAccessible(true); - $topic = $method->invokeArgs($this->mngr, array($name)); + $topic = $method->invokeArgs($this->mngr, [$name]); $this->mngr->onSubscribe($this->conn, $name); - $this->assertTrue($this->conn->WAMP->subscriptions->contains($topic)); + $this->assertTrue($this->conn->WAMP->subscriptions->offsetExists($topic)); } public function testDoubleSubscriptionFiresOnce() { @@ -135,14 +135,14 @@ public function testUnsubscribeRemovesTopicFromConnection() { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + //$method->setAccessible(true); $topic = $method->invokeArgs($this->mngr, array($name)); $this->mngr->onSubscribe($this->conn, $name); $this->mngr->onUnsubscribe($this->conn, $name); - $this->assertFalse($this->conn->WAMP->subscriptions->contains($topic)); + $this->assertFalse($this->conn->WAMP->subscriptions->offsetExists($topic)); } public function testOnPublishBubbles() { @@ -167,10 +167,10 @@ public function testOnCloseBubbles() { protected function topicProvider($name) { $class = new \ReflectionClass('Ratchet\Wamp\TopicManager'); $method = $class->getMethod('getTopic'); - $method->setAccessible(true); + //$method->setAccessible(true); $attribute = $class->getProperty('topicLookup'); - $attribute->setAccessible(true); + //$attribute->setAccessible(true); $topic = $method->invokeArgs($this->mngr, array($name));