1 <?php
2
3 namespace PayPal\Validation;
4
5 /**
6 * Class ArgumentValidator
7 *
8 * @package PayPal\Validation
9 */
10 class ArgumentValidator
11 {
12
13 /**
14 * Helper method for validating an argument that will be used by this API in any requests.
15 *
16 * @param $argument mixed The object to be validated
17 * @param $argumentName string|null The name of the argument.
18 * This will be placed in the exception message for easy reference
19 * @return bool
20 */
21 public static function validate($argument, $argumentName = null)
22 {
23 if ($argument === null) {
24 // Error if Object Null
25 throw new \InvalidArgumentException("$argumentName cannot be null");
26 } elseif (gettype($argument) == 'string' && trim($argument) == '') {
27 // Error if String Empty
28 throw new \InvalidArgumentException("$argumentName string cannot be empty");
29 }
30 return true;
31 }
32 }
33