I’ve gone on and implemented a logic “OR” method to allow for more flexible function arguments evaluation.
The problem
Trying to make function and methods argument evaluation a more streamlined process I do not want to lose any possibility a “normal” evaluation would allow.
In WordPress functions a recurring case is the one where a value might be a string
or a boolean
, an array
or a string
and so on and since I’m relying on such methods myself I could solve the problem with the current Args
implementation to go from this code
if ( !is_string($value) && !is_bool($value)){
throw new InvalidArgumentException('Value must be a string or a bool');
}
to this one using the assert()
method
Arg::_($value)->assert(is_string($value) || is_bool($value));
Or
Since the assert()
method solution alone “works” but does not “kicks” I’ve added the _or()
method to the class.
The check above might be rewritten using the new method like
Arg::_($value)->is_string()->_or()->is_bool();
In latin “vel” means “or” (as “aut” does) so I’ve added the vel()
and aut()
methods as aliases of the _or()
method too.