forked from LiveCarta/PayPal-PHP-SDK
Validation Package Testing
- Added More Unit Tests to Validation Classes - Updated Logic accordingly
This commit is contained in:
@@ -16,18 +16,17 @@ class ArgumentValidator
|
||||
* @param $argument mixed The object to be validated
|
||||
* @param $argumentName string|null The name of the argument.
|
||||
* This will be placed in the exception message for easy reference
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($argument, $argumentName = null)
|
||||
{
|
||||
if (
|
||||
$argument != null &&
|
||||
((gettype($argument) == 'string' && $argument == '') || is_array($argument) && empty($argument))
|
||||
) {
|
||||
//Throw an Exception for string or array
|
||||
throw new \InvalidArgumentException("$argumentName cannot be null or empty");
|
||||
} elseif ($argument === null) {
|
||||
//Generic Exception
|
||||
if ($argument === null) {
|
||||
// Error if Object Null
|
||||
throw new \InvalidArgumentException("$argumentName cannot be null");
|
||||
} else if (gettype($argument) == 'string' && trim($argument) == ''){
|
||||
// Error if String Empty
|
||||
throw new \InvalidArgumentException("$argumentName string cannot be empty");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user