public function count() : int
{
$count = count($this->getInnerIterator());
if (self::MODE_LIMIT === $this->mode) {
// We want real number of results - after applying limit
if (0 !== $this->offset) {
// Offset from beginning
$count -= $this->offset;
}
if (-1 !== $this->count && $count > $this->count) {
// Maximum number of items
$count = $this->count;
}
if ($count < 0) {
// We moved after end of inner iterator - offset is higher than count($this->getInnerIterator())
$count = 0;
}
}
return $count;
}