public function offsetSet($key, $entity)
    {
        $class = $this->entityClass;

        if ($entity instanceof $class) {
            if (!isset($key)) {
                $this->entities[] = $entity;
            } else {
                $this->entities[$key] = $entity;
            }
            return true;
        }

        throw new CollectionException(
            'The specified entity is not allowed for this collection.'
        );
    }