This repository has been archived on 2026-04-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PayPal-PHP-SDK/lib/PayPal/Validation/ArgumentValidator.php
japatel d11533110b Sanitize Input for Price Variables
- Updated the model to automatically format the price
- Updated the samples to reflect the new changes
- More Unit Tests
2014-11-03 16:31:03 -06:00

34 lines
1.0 KiB
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
*/
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
throw new \InvalidArgumentException("$argumentName cannot be null");
}
}
}