Bläddra i källkod

Merge pull request #461 from joanhey/hint

Enforce type hints
walkor 6 år sedan
förälder
incheckning
ab797e83db

+ 4 - 4
Connection/AsyncTcpConnection.php

@@ -26,7 +26,7 @@ class AsyncTcpConnection extends TcpConnection
     /**
      * Emitted when socket connection is successfully established.
      *
-     * @var callable
+     * @var callable|null
      */
     public $onConnect = null;
 
@@ -61,7 +61,7 @@ class AsyncTcpConnection extends TcpConnection
     /**
      * Connect start time.
      *
-     * @var string
+     * @var float
      */
     protected $_connectStartTime = 0;
 
@@ -109,7 +109,7 @@ class AsyncTcpConnection extends TcpConnection
      * @param array $context_option
      * @throws Exception
      */
-    public function __construct($remote_address, $context_option = null)
+    public function __construct($remote_address, array $context_option = array())
     {
         $address_info = \parse_url($remote_address);
         if (!$address_info) {
@@ -303,7 +303,7 @@ class AsyncTcpConnection extends TcpConnection
         // Check socket state.
         if ($address = \stream_socket_get_name($this->_socket, true)) {
             // Nonblocking.
-            \stream_set_blocking($this->_socket, 0);
+            \stream_set_blocking($this->_socket, false);
             // Compatible with hhvm
             if (\function_exists('stream_set_read_buffer')) {
                 \stream_set_read_buffer($this->_socket, 0);

+ 2 - 2
Connection/TcpConnection.php

@@ -269,7 +269,7 @@ class TcpConnection extends ConnectionInterface
      * @param array  $arguments
      * @return void
      */
-    public function __call($name, $arguments) {
+    public function __call($name, array $arguments) {
         // Try to emit custom function within protocol
         if (\method_exists($this->protocol, $name)) {
             try {
@@ -775,7 +775,7 @@ class TcpConnection extends ConnectionInterface
             return false;
         } elseif (0 === $ret) {
             // There isn't enough data and should try again.
-            return 0;
+            return false;
         }
         if (isset($this->onSslHandshake)) {
             try {

+ 2 - 2
Connection/UdpConnection.php

@@ -151,7 +151,7 @@ class UdpConnection extends ConnectionInterface
     /**
      * Is ipv4.
      *
-     * return bool.
+     * @return bool.
      */
     public function isIpV4()
     {
@@ -164,7 +164,7 @@ class UdpConnection extends ConnectionInterface
     /**
      * Is ipv6.
      *
-     * return bool.
+     * @return bool.
      */
     public function isIpV6()
     {

+ 3 - 2
Events/Ev.php

@@ -13,6 +13,7 @@
 namespace Workerman\Events;
 
 use Workerman\Worker;
+use EvWatcher;
 
 /**
  * ev eventloop
@@ -126,9 +127,9 @@ class Ev implements EventInterface
     /**
      * Timer callback.
      *
-     * @param \EvWatcher $event
+     * @param EvWatcher $event
      */
-    public function timerCallback($event)
+    public function timerCallback(EvWatcher $event)
     {
         $param    = $event->data;
         $timer_id = $param[4];

+ 5 - 3
Events/React/Base.php

@@ -12,14 +12,16 @@
  * @license   http://www.opensource.org/licenses/mit-license.php MIT License
  */
 namespace Workerman\Events\React;
+
 use Workerman\Events\EventInterface;
 use React\EventLoop\TimerInterface;
+use React\EventLoop\LoopInterface;
 
 /**
  * Class StreamSelectLoop
  * @package Workerman\Events\React
  */
-class Base implements \React\EventLoop\LoopInterface
+class Base implements LoopInterface
 {
     /**
      * @var array
@@ -37,7 +39,7 @@ class Base implements \React\EventLoop\LoopInterface
     protected $_signalHandlerMap = array();
 
     /**
-     * @var \React\EventLoop\LoopInterface
+     * @var LoopInterface
      */
     protected $_eventLoop = null;
 
@@ -58,7 +60,7 @@ class Base implements \React\EventLoop\LoopInterface
      * @param array $args
      * @return bool
      */
-    public function add($fd, $flag, $func, $args = array())
+    public function add($fd, $flag, $func, array $args = array())
     {
         $args = (array)$args;
         switch ($flag) {

+ 4 - 4
Lib/Timer.php

@@ -40,17 +40,17 @@ class Timer
     /**
      * event
      *
-     * @var \Workerman\Events\EventInterface
+     * @var EventInterface
      */
     protected static $_event = null;
 
     /**
      * Init.
      *
-     * @param \Workerman\Events\EventInterface $event
+     * @param EventInterface $event
      * @return void
      */
-    public static function init($event = null)
+    public static function init(EventInterface $event = null)
     {
         if ($event) {
             self::$_event = $event;
@@ -81,7 +81,7 @@ class Timer
      * @param callable $func
      * @param mixed    $args
      * @param bool     $persistent
-     * @return int/false
+     * @return int|false
      */
     public static function add($time_interval, $func, $args = array(), $persistent = true)
     {

+ 4 - 4
Protocols/ProtocolInterface.php

@@ -26,8 +26,8 @@ interface ProtocolInterface
      * If length is unknow please return 0 that mean wating more data.
      * If the package has something wrong please return false the connection will be closed.
      *
-     * @param ConnectionInterface $connection
      * @param string              $recv_buffer
+     * @param ConnectionInterface $connection
      * @return int|false
      */
     public static function input($recv_buffer, ConnectionInterface $connection);
@@ -35,17 +35,17 @@ interface ProtocolInterface
     /**
      * Decode package and emit onMessage($message) callback, $message is the result that decode returned.
      *
-     * @param ConnectionInterface $connection
      * @param string              $recv_buffer
+     * @param ConnectionInterface $connection
      * @return mixed
      */
     public static function decode($recv_buffer, ConnectionInterface $connection);
 
     /**
      * Encode package brefore sending to client.
-     *
-     * @param ConnectionInterface $connection
+     * 
      * @param mixed               $data
+     * @param ConnectionInterface $connection
      * @return string
      */
     public static function encode($data, ConnectionInterface $connection);

+ 1 - 1
WebServer.php

@@ -65,7 +65,7 @@ class WebServer extends Worker
      * @param string $socket_name
      * @param array  $context_option
      */
-    public function __construct($socket_name, $context_option = array())
+    public function __construct($socket_name, array $context_option = array())
     {
         list(, $address) = \explode(':', $socket_name, 2);
         parent::__construct('http:' . $address, $context_option);

+ 6 - 6
Worker.php

@@ -473,7 +473,7 @@ class Worker
     /**
      * Graceful stop or not.
      *
-     * @var string
+     * @var bool
      */
     protected static $_gracefulStop = false;
 
@@ -1400,7 +1400,7 @@ class Worker
         $pipes       = array();
         $process     = \proc_open("php \"$start_file\" -q", $descriptorspec, $pipes);
         $std_handler = \fopen($std_file, 'a+');
-        \stream_set_blocking($std_handler, 0);
+        \stream_set_blocking($std_handler, false);
 
         if (empty(static::$globalEvent)) {
             static::$globalEvent = new Select();
@@ -2083,8 +2083,8 @@ class Worker
 
     /**
      * Safe Echo.
-     * @param $msg
-     * @param bool $decorated
+     * @param string $msg
+     * @param bool   $decorated
      * @return bool
      */
     public static function safeEcho($msg, $decorated = false)
@@ -2142,7 +2142,7 @@ class Worker
      * @param string $socket_name
      * @param array  $context_option
      */
-    public function __construct($socket_name = '', $context_option = array())
+    public function __construct($socket_name = '', array $context_option = array())
     {
         // Save all worker instances.
         $this->workerId                    = \spl_object_hash($this);
@@ -2228,7 +2228,7 @@ class Worker
             }
 
             // Non blocking.
-            \stream_set_blocking($this->_mainSocket, 0);
+            \stream_set_blocking($this->_mainSocket, false);
         }
 
         $this->resumeAccept();