Commits

Thomas Weinert  committed a7214d0

Code Cleanup, Define properties and types

  • Participants
  • Parent commits 54b6698

Comments (0)

Files changed (19)

File src/Carica/Io/Callbacks.php

 namespace Carica\Io {
 
   /**
-   * Manage a list Callables, the Callables can be uses as one callable, too.
+   * Manage a list Callable elements, the list can be uses as one callable, too.
+   *
+   * @property Callable add
+   * @property Callable remove
+   * @property Callable fire
+   * @property Callable lock
+   * @property Callable disable
    */
   class Callbacks implements \IteratorAggregate, \Countable {
 
      * Add a new callable, and return itself for chaining
      *
      * @param callable $callback
-     * @return \Carica\Io\Callbacks
+     * @return Callbacks
      */
     public function add(Callable $callback) {
       $hash = $this->getCallableHash($callback);
      * Remove an callable, and return itself for chaining
      *
      * @param callable $callback
-     * @return \Carica\Io\Callbacks
+     * @return Callbacks
      */
     public function remove(Callable $callback) {
       $hash = $this->getCallableHash($callback);
     /**
      * Remove all callables
      *
-     * @return \Carica\Io\Callbacks
+     * @return Callbacks
      */
     public function clear() {
       if (!$this->_locked) {
     /**
      * Lock the list, do now allow chanes any more.
      *
-     * @return \Carica\Io\Callbacks
+     * @return Callbacks
      */
     public function lock() {
       $this->_locked = TRUE;
     /**
      * Disable the execution of the callbacks in the list
      *
-     * @return \Carica\Io\Callbacks
+     * @return Callbacks
      */
     public function disable() {
       $this->_disabled = TRUE;

File src/Carica/Io/Deferred.php

     /**
      * An promise for this object
      * .
-     * @var \Carica\Io\Deferred\Promise
+     * @var Deferred\Promise
      */
     private $_promise = NULL;
 
     /**
      * Callbacks if the object is resolved
      * .
-     * @var \Carica\Io\Callbacks
+     * @var Callable|Callbacks
      */
     private $_done = NULL;
     /**
      * Callbacks if the object is rejected
      * .
-     * @var \Carica\Io\Callbacks
+     * @var Callable|Callbacks
      */
     private $_failed = NULL;
     /**
      * Callbacks if the object is notified about a progress
      * .
-     * @var \Carica\Io\Callbacks
+     * @var Callable|Callbacks
      */
     private $_progress = NULL;
 
      * resolved or reject
      *
      * @param Callable $callback
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function always(Callable $callback) {
       $this->_done->add($callback);
      * Add a callback that will be executed if the object is resolved
      *
      * @param Callable $callback
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function done(Callable $callback) {
       $this->_done->add($callback);
      * Add a callback that will be eecuted if the object was rejected
      *
      * @param Callable $callback
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function fail(Callable $callback) {
       $this->_failed->add($callback);
      * @param Callable $doneFilter
      * @param Callable $failFilter
      * @param Callable $progressFilter
-     * @return \Carica\Io\Deferred\Promise
+     * @return Deferred\Promise
      */
     public function pipe(
       Callable $doneFilter = NULL,
      * Add a callback that will be executed if the object is notified about progress
      *
      * @param Callable $callback
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function progress(Callable $callback) {
       $this->_progress->add($callback);
      * Creates and returns a promise attached to this object, a promise is used to
      * attach callbacks and validate the status. But has no methods to change the status.
      *
-     * @return \Carica\Io\Deferred\Promise
+     * @return Deferred\Promise
      */
     public function promise() {
       if (NULL === $this->_promise) {
      * Finalize the object and set the status to rejected - the action has failed.
      * This will execute all callbacks attached with fail() or always()
      *
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function reject() {
       if ($this->_state == self::STATE_PENDING) {
      * Finalize the object and set the status to rejected - the action was successful.
      * This will execute all callbacks attached with done() or always()
      *
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function resolve() {
       if ($this->_state == self::STATE_PENDING) {
      * @param Callable|array(Callable) $done
      * @param Callable|array(Callable) $fail
      * @param Callable|array(Callable) $progress
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public function then($done = NULL, $fail = NULL, $progress = NULL) {
       $this->addCallbacksIfProvided(array($this, 'done'), $done);
     /**
      * Static method to the create a new Deferred object.
      *
-     * @return \Carica\Io\Deferred
+     * @return Deferred
      */
     public static function create() {
       return new Deferred();
      * Provides a way to execute callback functions based on one or more
      * objects, usually Deferred objects that represent asynchronous events.
      *
-     * @return \Carica\Io\Deferred\Promise
+     * @return Deferred\Promise
      */
     public static function when() {
       $arguments = func_get_args();

File src/Carica/Io/Event/Emitter.php

      * Add a listener object. If a callable is added, it is wrapped into a listener
      *
      * @param string $event
-     * @param Emitter\Listener $listener
+     * @param \Callable|Emitter\Listener $listener
      */
     public function on($event, $listener) {
       $listener = $listener instanceOf Emitter\Listener
      * into a listener
      *
      * @param string $event
-     * @param Emitter\Listener $listener
+     * @param \Callable|Emitter\Listener $listener
      */
     public function once($event, $listener) {
       $listener = $listener instanceOf Emitter\Listener\Once
      * Remode the specified listenr from the event
      *
      * @param string $event
-     * @param Emitter\Listener $listener
+     * @param \Callable|Emitter\Listener $listener
      */
     public function removeListener($event, $listener) {
       if (isset($this->_events[$event])) {
      * Return an list of a listeners attached to the event
      *
      * @param string $event
-     * @return array(Emitter\Listener)
+     * @return array(\Callable|Emitter\Listener)
      */
     public function listeners($event) {
       return isset($this->_events[$event]) ? $this->_events[$event] : array();

File src/Carica/Io/Event/Emitter/Listener/On.php

 
   use Carica\Io\Event;
 
+  /**
+   * @property Event\Emitter $emitter
+   * @property string $event
+   * qproperty Callable $callback
+   */
   class On implements Event\Emitter\Listener {
 
     private $_emitter = NULL;
     }
 
     public function getCallback() {
-      return $this->callback;
+      return $this->_callback;
     }
   }
 }

File src/Carica/Io/Event/Emitter/Listener/Once.php

 
   use Carica\Io\Event;
 
+  /**
+   * @property Event\Emitter $emitter
+   * @property string $event
+   * qproperty Callable $callback
+   */
   class Once extends On {
 
     public function __invoke() {
-      $this->emitter->removeListener($this->event, $callback = $this->callback);
+      $this->emitter->removeListener($this->event, $callback = $this->getCallback());
       call_user_func_array($callback, func_get_args());
     }
   }

File src/Carica/Io/Event/Loop/Libevent/Listener/Stream.php

     private $_write = NULL;
     private $_stream = NULL;
 
+    /**
+     * @param Libevent $loop
+     * @param Resource $stream
+     */
     public function __construct(Event\Loop\Libevent $loop, $stream) {
       $that = $this;
       parent::__construct(
       if (is_null($this->_read)) {
         $this->_read = new Io\Callbacks();
       }
-      $this->_read->add($result = new Stream\Callback($this, $this->_read->remove, $callback));
+      /**
+       * @var Callable $result
+       */
+      $result = new Stream\Callback($this, $this->_read->remove, $callback);
+      $this->_read->add($result);
       $this->update();
       return $result;
     }
       if (is_null($this->_write)) {
         $this->_write = new Io\Callbacks();
       }
-      $this->_write->add($result = new Stream\Callback($this, $this->_write->remove, $callback));
+      /**
+       * @var Callable $result
+       */
+      $result = new Stream\Callback($this, $this->_write->remove, $callback);
+      $this->_write->add($result);
       $this->update();
       return $result;
     }
         if (is_null($this->_event)) {
           $this->_event = $event = event_new();
           $that = $this;
+          /** @noinspection PhpUnusedParameterInspection */
           $callback = function ($stream, $events) use ($event, $that, &$callback) {
             if (!$that->isCancelled()) {
               call_user_func($this->getCallback(), $events);
       $this->_read = NULL;
       $this->_write = NULL;
       $this->_stream = NULL;
-      parent::free();
     }
   }
 }

File src/Carica/Io/Network/Connection.php

     use Io\Event\Emitter\Aggregation;
     use Io\Event\Loop\Aggregation;
 
+    /**
+     * @var object
+     */
     private $_listener = NULL;
 
+    /**
+     * @var bool|resource
+     */
     private $_stream = FALSE;
 
+    /**
+     * @param Io\Stream $stream
+     */
     public function __construct($stream) {
       $this->resource($stream);
     }

File src/Carica/Io/Network/Http/Header.php

      */
     public function setData($data) {
       $this->_values = new \ArrayObject;
-      if (is_array($data) || $data instanceOf Traversable) {
+      if (is_array($data) || $data instanceOf \Traversable) {
         foreach ($data as $value) {
           $this->_values[] = trim((string)$value);
         }
      * @return string
      */
     public function __toString() {
+      /** @noinspection PhpParamsInspection */
       return (string)end($this->_values);
     }
 
       case 'name' :
         return $this->_name;
       case 'value' :
+        /** @noinspection PhpParamsInspection */
         return end($this->_values);
       case 'values' :
         return $this->_values;

File src/Carica/Io/Network/Http/Request.php

 
   use Carica\Io;
 
+  /**
+   * @property string $method
+   * @property string $version
+   * @property string $url
+   * @property string $path
+   * @property Connection $connection
+   * @property Headers $headers
+   * @property Request\Query $query
+   */
   class Request {
 
     private $_patternStatus =
       }
     }
 
+    /**
+     * @return Response
+     */
     public function createResponse() {
       return new Response($this->connection());
     }

File src/Carica/Io/Network/Http/Response.php

 
   use Carica\Io;
 
+  /**
+   * @property string $version
+   * @property integer $status
+   * @property Connection $connection
+   * @property Headers $headers
+   * @property Response\Content $content
+   */
   class Response {
 
     public $_version = '1.0';
 
     private $_status = 200;
+
     protected $_statusStrings = array(
       100 => 'Continue',
       101 => 'Switching Protocols',

File src/Carica/Io/Network/Http/Response/Content/Html.php

   use Carica\Io\Network;
   use Carica\Io\Network\Http\Response;
 
+  /**
+   * @property \DOMDocument $document
+   */
   class Html extends Response\Content {
 
     private $_document = NULL;

File src/Carica/Io/Network/Http/Response/Content/Xml.php

   use Carica\Io\Network;
   use Carica\Io\Network\Http\Response;
 
+  /**
+   * @property \DOMDocument $document
+   */
   class Xml extends Response\Content {
 
     private $_document = NULL;

File src/Carica/Io/Network/Http/Response/Error.php

   use Carica\Io;
   use Carica\Io\Network\Http;
 
+  /**
+   * @property \DOMDocument $document
+   */
   class Error extends Http\Response {
 
     private $_template = '
     public function __construct(Http\Request $request, $status = 500, $message = NULL) {
       parent::__construct($request->connection());
       $this->setStatus($status);
-      $this->content = new Http\Response\Content\Html();
+      $this->content = $content = new Http\Response\Content\Html();
       if (NULL === $message) {
         $message = $this->_statusStrings[$this->status];
       }
-      $this->content->document->loadHtml(
+      $content->document->loadHtml(
         sprintf(
           $this->_template,
           (int)$status,

File src/Carica/Io/Network/Http/Route/File.php

     }
 
     public function setEncoding($mimetype, $encoding) {
-      $this->_encoding[$mimetype] = (string)$encoding;
+      $this->_encodings[$mimetype] = (string)$encoding;
     }
 
     public function getEncoding($mimetype) {

File src/Carica/Io/Network/Server.php

           $that = $this;
           $this->loop()->setStreamReader(
             function() use ($that) {
-              $that->read();
+              $that->accept();
             },
             $stream
           );
 
     public function close() {
       if ($this->isActive()) {
-        stream_socket_shutdown($this->_stream, STREAM_SHUT_RDWR);
+        stream_socket_shutdown($this->resource(), STREAM_SHUT_RDWR);
       }
       $this->resource(FALSE);
     }
 
-    public function read($bytes = 0) {
-      if ($this->isActive() && ($stream = @stream_socket_accept($this->_stream, 1, $peer))) {
+    public function accept() {
+      if ($this->isActive() && ($stream = @stream_socket_accept($this->resource(), 1, $peer))) {
         $this->events()->emit('connection', $stream, $peer);
       }
     }

File src/Carica/Io/Stream/File.php

      * the an event listener to the loop, that calls read on new data
      *
      * @param string $resource
-     * @return NULL
+     * @return NULL|resource
      */
     public function resource($resource = NULL) {
       if ($resource === FALSE) {

File src/Carica/Io/Stream/Serial.php

     use Event\Loop\Aggregation;
 
     private $_device = 0;
-    private $_command = '';
     private $_resource = NULL;
     private $_listener = NULL;
 

File src/Carica/Io/Stream/Serial/Dio.php

     use Event\Loop\Aggregation;
 
     private $_device = 0;
-    private $_command = '';
     private $_resource = NULL;
     private $_listener = NULL;
 
-    private $_reading = FALSE;
-
     public function __construct($device, $baud = 57600)
     {
       $this->_device = new Device($device, $baud);

File src/Carica/Io/Stream/Serial/Factory.php

 
 namespace Carica\Io\Stream\Serial {
 
+  use Carica\Io\Stream;
+
   class Factory {
 
     /**
         } elseif (!$use) {
           self::$_useDio = FALSE;
         } else {
-          throw new LogicException('Extension "dio" not available.');
+          throw new \LogicException('Extension "dio" not available.');
         }
       } elseif (NULL == self::$_useDio) {
         self::$_useDio = extension_loaded('dio');