Eloquent\Phony\Spy\ArraySpy::valid PHP Method

valid() public method

Returns true if the current iterator position is valid.
public valid ( ) : boolean
return boolean True if the current iterator position is valid.
    public function valid()
    {
        if (!$this->isUsed) {
            $this->call->addIterableEvent($this->callEventFactory->createUsed());
            $this->isUsed = true;
        }
        $key = key($this->array);
        $isValid = null !== $key;
        if ($this->isConsumed) {
            return $isValid;
        }
        if ($isValid) {
            $this->call->addIterableEvent($this->callEventFactory->createProduced($key, current($this->array)));
        } else {
            $this->call->setEndEvent($this->callEventFactory->createConsumed());
            $this->isConsumed = true;
        }
        return $isValid;
    }