Automattic\WooCommerce\Api\Pagination
PaginationParams::validate_limit
Validate a first / last argument.
Method of the class: PaginationParams{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = PaginationParams::validate_limit( $name, ?int $value ): void;
- $name(string) (required)
- The argument name, for the error message.
- ?int $value(required)
- .
PaginationParams::validate_limit() PaginationParams::validate limit code WC 10.9.1
private static function validate_limit( string $name, ?int $value ): void {
if ( null === $value ) {
return;
}
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML output; serialized as JSON in the GraphQL error response.
if ( $value < 0 ) {
throw new \InvalidArgumentException(
sprintf( 'Argument `%s` must be zero or greater.', $name )
);
}
if ( $value > self::MAX_PAGE_SIZE ) {
throw new \InvalidArgumentException(
sprintf(
'Argument `%s` exceeds the maximum page size of %d.',
$name,
self::MAX_PAGE_SIZE
)
);
}
// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
}