0

Php-docs for class implements the Iterator interface

Hello. How can I help PhpShtorm understand that the return type for the iteration is a Model?

I have model and collection:

class Model {     public function getName(){} } class ModelCollection implements \Iterator {     /**      * @var Model[]      */     private $_models = array();     private $_position = 0;     /**      * @return Model      */     public function current() {         return $this->_models[$this->_position];     }     /** ... other Iterator methods ... */ }


Now I write every time you iterate a return type. But wants the type is determined automatically or by php-doc current method or something else :)

$collection = new ModelCollection();

/**
* @var Model $model
*/
foreach($collection as $model) {
   echo $model->getName();
}

1 comment

Please sign in to leave a comment.