Better than yesterday.

DRYer function arguments checks

I’ve grown tired of checking arguments in functions and methods calls repeating the same checks over and over.

Type hinting

PHP allows for a limited type hinting and this means that checks are required in each function and method accepting arguments to make sure exceptions are thrown any time functions and methods input arguments do not match a certain pattern.
This checking can be kept DRY ‘) to a point and, furthermore, will require testing.
I’ve tried to streamline this chore a little with the Arg class to make checks like these

if(!is_string($s)) {
throw new InvalidArgumentException('Argument must be a string');
}
if(!strlen($s) < 10) {
throw new InvalidArgumentException('String must be at least 10 chars long');
}
if(!strlen($s) > 100) {
throw new InvalidArgumentException('String must be at most 100 chars long');
}
if(!preg_match($this->name_pattern, $s)){
throw new InvalidArgumentException('String must be match the name pattern');
}