protected function prepareObjectsSlice($itemsPerPage, $offset)
    {
        if ($this->objects instanceof QueryResultInterface) {
            $currentRange = $offset + $itemsPerPage;
            $endOfRange = \min($currentRange, \count($this->objects));
            $query = $this->objects->getQuery();
            $query->setLimit($itemsPerPage);
            if ($offset > 0) {
                $query->setOffset($offset);
                if ($currentRange > $endOfRange) {
                    $newLimit = $endOfRange - $offset;
                    $query->setLimit($newLimit);
                }
            }
            $modifiedObjects = $query->execute();

            return $modifiedObjects;
        }
        if ($this->objects instanceof ObjectStorage) {
            $modifiedObjects = [];
            $objectArray = $this->objects->toArray();
            $endOfRange = \min($offset + $itemsPerPage, \count($objectArray));
            for ($i = $offset; $i < $endOfRange; ++$i) {
                $modifiedObjects[] = $objectArray[$i];
            }

            return $modifiedObjects;
        }
        if (\is_array($this->objects)) {
            $modifiedObjects = \array_slice($this->objects, $offset, $itemsPerPage);

            return $modifiedObjects;
        }
        throw new \InvalidArgumentException(
            'The view helper "' . static::class
            . '" accepts as argument "QueryResultInterface", "\SplObjectStorage", "ObjectStorage" or an array. '
            . 'given: ' . \get_class($this->objects),
            1385547291
        );
    }