Skip to content

Commit

Permalink
Throw exception with bad per page value
Browse files Browse the repository at this point in the history
  • Loading branch information
roborourke committed Sep 22, 2021
1 parent af07f20 commit a845dfa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions inc/MediaResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace AssetManagerFramework;

use RangeException;

class MediaResponse {

/**
Expand Down Expand Up @@ -39,8 +41,20 @@ class MediaResponse {
* @param int $total The total number of results available.
* @param int $per_page The number of items requested per page, defaults to 40 in media
* modal requests.
* @throws RangeException If $per_page value is less than or equal to 0.
*/
public function __construct( ?MediaList $media_list = null, int $total = 0, int $per_page = 40 ) {
// Fail early if provided per page value is not valid.
if ( $per_page <= 0 ) {
throw new RangeException(
sprintf(
/* translators: %d: Items per page value in error message */
__( 'Media items per page value must be greater than zero, %d given.', 'asset-manager-framework' ),
$per_page
)
);
}

$this->media_list = $media_list ?? new MediaList();
$this->total = $total;
$this->per_page = $per_page;
Expand Down

0 comments on commit a845dfa

Please sign in to comment.