protected function resolveEntityClass($entity)
    {
        // We first check if the entity is traversable and we'll resolve
        // the entity based on the first item of the object.
        if ($this->isTraversable($entity)) {
            if (!count($entity)) {
                throw new \InvalidArgumentException('Length of Entity collection must be greater than 0');
            }

            $firstEntityItem = ($entity instanceof \Iterator)
                ? $entity->current()
                : current($entity);

            return $this->resolveEntityClass($firstEntityItem);
        }

        if (is_object($entity)) {
            return get_class($entity);
        }

        if (is_string($entity)) {
            return $entity;
        }

        throw new \InvalidArgumentException('Invalid entity type');
    }