Skip to content

Commit

Permalink
Add some defensive checks
Browse files Browse the repository at this point in the history
  • Loading branch information
anagh-p committed May 14, 2018
1 parent e53c014 commit 7364cb8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Quintype/Caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ private function buildCollectionKeys($params)
{
$collectionKeys = [];
foreach ($params['storiesToCache'] as $key => $collection) {
if (isset($collection['items']) && isset($collection['id'])) {
array_push($collectionKeys, 'c/'.$params['publisherId'].'/'. trim($collection['id']));
}
}
return implode(' ', $collectionKeys);
}
Expand All @@ -26,9 +28,11 @@ private function buildStoryKeysFromCollections($params)
{
$stories = [];
foreach ($params['storiesToCache'] as $key => $collection) {
foreach (array_slice($collection['items'], 0, 5) as $key => $item) {
if ($item['type'] === 'story') {
array_push($stories, $item['story']);
if (isset($collection['items']) && sizeof($collection['items']) > 5 ) {
foreach (array_slice($collection['items'], 0, 5) as $key => $item) {
if ($item['type'] === 'story') {
array_push($stories, $item['story']);
}
}
}
}
Expand Down

0 comments on commit 7364cb8

Please sign in to comment.