public function restrictTo(string $type)
    {
        if (count($this) > 0) {
            throw new CollectionException('Type restriction could not be applied to a non empty collection');
        }

        $this->type = $type;

        return $this;
    }
public function restrictTo(string $type)
    {
        if (count($this) > 0) {
            throw new CollectionException('Type restriction could not be applied to a non empty collection');
        }

        $this->type = $type;

        return $this;
    }
public function restrictTo ( string $ type ) { if ( count ( $ this ) > 0 ) { throw new CollectionException ( 'Type restriction could not be applied to a non empty collection' ) ; } $ this -> type = $ type ; return $ this ; }
Restricts the values of the collection to a given type

@param string $type

@return $this
Restricts the values of the collection to a given type