public function factory(string $name, $arg = null): Rule
    {
        if (!array_key_exists($name, $this->definitions)) {
            throw new \InvalidArgumentException("No rule registered with name: $name");
        }
        $vrule = is_array($arg) ?
            call_user_func_array($this->definitions[$name], $arg) :
            call_user_func($this->definitions[$name], $arg);
        if (!$vrule instanceof Rule) {
            throw new \UnexpectedValueException('Definitions must return Rule objects');
        }
        return $vrule;
    }
public function factory(string $name, $arg = null): Rule
    {
        if (!array_key_exists($name, $this->definitions)) {
            throw new \InvalidArgumentException("No rule registered with name: $name");
        }
        $vrule = is_array($arg) ?
            call_user_func_array($this->definitions[$name], $arg) :
            call_user_func($this->definitions[$name], $arg);
        if (!$vrule instanceof Rule) {
            throw new \UnexpectedValueException('Definitions must return Rule objects');
        }
        return $vrule;
    }
public function factory ( string $ name , $ arg = null ) : Rule { if ( ! array_key_exists ( $ name , $ this -> definitions ) ) { throw new \ InvalidArgumentException ( "No rule registered with name: $name" ) ; } $ vrule = is_array ( $ arg ) ? call_user_func_array ( $ this -> definitions [ $ name ] , $ arg ) : call_user_func ( $ this -> definitions [ $ name ] , $ arg ) ; if ( ! $ vrule instanceof Rule ) { throw new \ UnexpectedValueException ( 'Definitions must return Rule objects' ) ; } return $ vrule ; }
Constructs a validation rule.

@param string $name A string name
@param mixed $arg Optional constructor argument, or an array of arguments
@return \Caridea\Validate\Rule The instantiated rule
@throws \InvalidArgumentException if the rule name is not registered
@throws \UnexpectedValueException if the factory returns a non-Rule
Constructs a validation rule .