Просмотр исходного кода

Merge pull request #459 from joanhey/type

Enforce type hints
walkor 6 лет назад
Родитель
Сommit
38b59d0d54
5 измененных файлов с 17 добавлено и 15 удалено
  1. 2 2
      Connection/TcpConnection.php
  2. 2 2
      Protocols/Websocket.php
  3. 8 7
      Protocols/Ws.php
  4. 3 2
      WebServer.php
  5. 2 2
      Worker.php

+ 2 - 2
Connection/TcpConnection.php

@@ -796,10 +796,10 @@ class TcpConnection extends ConnectionInterface
     /**
      * This method pulls all the data out of a readable stream, and writes it to the supplied destination.
      *
-     * @param TcpConnection $dest
+     * @param self $dest
      * @return void
      */
-    public function pipe($dest)
+    public function pipe(self $dest)
     {
         $source              = $this;
         $this->onMessage     = function ($source, $data) use ($dest) {

+ 2 - 2
Protocols/Websocket.php

@@ -336,10 +336,10 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
      * Websocket handshake.
      *
      * @param string                              $buffer
-     * @param \Workerman\Connection\TcpConnection $connection
+     * @param TcpConnection $connection
      * @return int
      */
-    protected static function dealHandshake($buffer, $connection)
+    protected static function dealHandshake($buffer, TcpConnection $connection)
     {
         // HTTP protocol.
         if (0 === \strpos($buffer, 'GET')) {

+ 8 - 7
Protocols/Ws.php

@@ -16,6 +16,7 @@ namespace Workerman\Protocols;
 use Workerman\Worker;
 use Workerman\Lib\Timer;
 use Workerman\Connection\TcpConnection;
+use Workerman\Connection\ConnectionInterface;
 
 /**
  * Websocket protocol for client.
@@ -43,7 +44,7 @@ class Ws
      * @param ConnectionInterface $connection
      * @return int
      */
-    public static function input($buffer, $connection)
+    public static function input($buffer, ConnectionInterface $connection)
     {
         if (empty($connection->handshakeStep)) {
             Worker::safeEcho("recv data before handshake. Buffer:" . bin2hex($buffer) . "\n");
@@ -227,7 +228,7 @@ class Ws
      * @param ConnectionInterface $connection
      * @return string
      */
-    public static function encode($payload, $connection)
+    public static function encode($payload, ConnectionInterface $connection)
     {
         if (empty($connection->websocketType)) {
             $connection->websocketType = self::BINARY_TYPE_BLOB;
@@ -299,7 +300,7 @@ class Ws
      * @param ConnectionInterface $connection
      * @return string
      */
-    public static function decode($bytes, $connection)
+    public static function decode($bytes, ConnectionInterface $connection)
     {
         $data_length = \ord($bytes[1]);
 
@@ -352,10 +353,10 @@ class Ws
     /**
      * Send websocket handshake.
      *
-     * @param \Workerman\Connection\TcpConnection $connection
+     * @param TcpConnection $connection
      * @return void
      */
-    public static function sendHandshake($connection)
+    public static function sendHandshake(TcpConnection $connection)
     {
         if (!empty($connection->handshakeStep)) {
             return;
@@ -397,10 +398,10 @@ class Ws
      * Websocket handshake.
      *
      * @param string                              $buffer
-     * @param \Workerman\Connection\TcpConnection $connection
+     * @param TcpConnection $connection
      * @return int
      */
-    public static function dealHandshake($buffer, $connection)
+    public static function dealHandshake($buffer, TcpConnection $connection)
     {
         $pos = \strpos($buffer, "\r\n\r\n");
         if ($pos) {

+ 3 - 2
WebServer.php

@@ -15,6 +15,7 @@ namespace Workerman;
 
 use Workerman\Protocols\Http;
 use Workerman\Protocols\HttpCache;
+use Workerman\Connection\TcpConnection;
 
 /**
  *  WebServer.
@@ -145,10 +146,10 @@ class WebServer extends Worker
     /**
      * Emit when http message coming.
      *
-     * @param Connection\TcpConnection $connection
+     * @param TcpConnection $connection
      * @return void
      */
-    public function onMessage($connection)
+    public function onMessage(TcpConnection $connection)
     {
         // REQUEST_URI.
         $workerman_url_info = \parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

+ 2 - 2
Worker.php

@@ -1450,10 +1450,10 @@ class Worker
     /**
      * Fork one worker process.
      *
-     * @param \Workerman\Worker $worker
+     * @param self $worker
      * @throws Exception
      */
-    protected static function forkOneWorkerForLinux($worker)
+    protected static function forkOneWorkerForLinux(self $worker)
     {
         // Get available worker id.
         $id = static::getId($worker->workerId, 0);