protected function singleEntity($entity)
    {
        if (empty($entity)) {
            return null;
        }

        $singleEntity = $entity;

        if (is_array($entity)) {
            if (count($entity) > 1) {
                throw RuntimeException::multipleResultsFound();
            }

            $singleEntity = reset($entity);
        }

        $entityClass = $this->getEntityName();

        if (!$singleEntity instanceof $entityClass) {
            throw InvalidArgumentException::invalidEntityType(
                $this->getEntityName(),
                $singleEntity
            );
        }

        return $singleEntity;
    }
protected function singleEntity($entity)
    {
        if (empty($entity)) {
            return null;
        }

        $singleEntity = $entity;

        if (is_array($entity)) {
            if (count($entity) > 1) {
                throw RuntimeException::multipleResultsFound();
            }

            $singleEntity = reset($entity);
        }

        $entityClass = $this->getEntityName();

        if (!$singleEntity instanceof $entityClass) {
            throw InvalidArgumentException::invalidEntityType(
                $this->getEntityName(),
                $singleEntity
            );
        }

        return $singleEntity;
    }
protected function singleEntity ( $ entity ) { if ( empty ( $ entity ) ) { return null ; } $ singleEntity = $ entity ; if ( is_array ( $ entity ) ) { if ( count ( $ entity ) > 1 ) { throw RuntimeException :: multipleResultsFound ( ) ; } $ singleEntity = reset ( $ entity ) ; } $ entityClass = $ this -> getEntityName ( ) ; if ( ! $ singleEntity instanceof $ entityClass ) { throw InvalidArgumentException :: invalidEntityType ( $ this -> getEntityName ( ) , $ singleEntity ) ; } return $ singleEntity ; }
Makes sure a result contains a single result.

@param  array|null|object entity

@return object|null

@throws RuntimeException         If mulitple entities are found in the array.
@throws InvalidArgumentException If the object is not an entity.
Makes sure a result contains a single result .