Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
PagedList: Verify that all items are pinterest objects
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Mar 13, 2016
1 parent b4f32ab commit 811d5ef
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Pinterest/Objects/PagedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Pinterest\Objects;

use InvalidArgumentException;

/**
* This class represents a paged list.
*
Expand Down Expand Up @@ -42,6 +44,7 @@ final class PagedList
*/
public function __construct(array $items = array(), $nextUrl = null)
{
$this->guardThatTheseAreAllPinterestObjects($items);
$this->items = $items;
$this->nextUrl = $nextUrl;
}
Expand Down Expand Up @@ -75,4 +78,23 @@ public function getNextUrl()
{
return $this->nextUrl;
}

/**
* Checks if all items are pinterest objects.
*
* @param array $items
*
* @throws InvalidArgumentException
*/
private function guardThatTheseAreAllPinterestObjects(array $items)
{
foreach ($items as $item) {
if (! ($item instanceof BaseObject)) {
throw new InvalidArgumentException(sprintf(
'Expected "Pinterest\Objects\BaseObject" but instead got: "%s"',
is_object($item) ? get_class($item) : gettype($item)
));
}
}
}
}

0 comments on commit 811d5ef

Please sign in to comment.