public function valid()
{
if (!$this->isUsed) {
$this->call->addIterableEvent($this->callEventFactory->createUsed());
if ($this->traversable instanceof IteratorAggregate) {
$this->iterator = $this->traversable->getIterator();
} else {
$this->iterator = $this->traversable;
}
$this->isUsed = true;
}
if ($isValid = $this->iterator->valid()) {
$this->key = $this->iterator->key();
$this->value = $this->iterator->current();
} else {
$this->key = null;
$this->value = null;
}
if ($this->isConsumed) {
return $isValid;
}
if ($isValid) {
$this->call->addIterableEvent($this->callEventFactory->createProduced($this->key, $this->value));
} else {
$this->call->setEndEvent($this->callEventFactory->createConsumed());
$this->isConsumed = true;
}
return $isValid;
}