mirror of
https://github.com/Karaka-Management/Resources.git
synced 2026-01-11 05:18:40 +00:00
33 lines
957 B
PHP
33 lines
957 B
PHP
<?php
|
|
|
|
namespace PayPal\Validation;
|
|
|
|
/**
|
|
* Class ArgumentValidator
|
|
*
|
|
* @package PayPal\Validation
|
|
*/
|
|
class ArgumentValidator
|
|
{
|
|
|
|
/**
|
|
* Helper method for validating an argument that will be used by this API in any requests.
|
|
*
|
|
* @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) {
|
|
// Error if Object Null
|
|
throw new \InvalidArgumentException("$argumentName cannot be null");
|
|
} elseif (gettype($argument) == 'string' && trim($argument) == '') {
|
|
// Error if String Empty
|
|
throw new \InvalidArgumentException("$argumentName string cannot be empty");
|
|
}
|
|
return true;
|
|
}
|
|
}
|