Skip to content

Commit

Permalink
Return false instead of collection if adjacent item not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Karmalakas committed Jul 6, 2021
1 parent 8af1229 commit 5bb439c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions system/src/Grav/Common/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function isLast($path): bool
*
* @param string $path
*
* @return PageInterface The previous item.
* @return PageInterface|false The previous item.
*/
public function prevSibling($path)
{
Expand All @@ -276,7 +276,7 @@ public function prevSibling($path)
*
* @param string $path
*
* @return PageInterface The next item.
* @return PageInterface|false The next item.
*/
public function nextSibling($path)
{
Expand All @@ -288,7 +288,7 @@ public function nextSibling($path)
*
* @param string $path
* @param int $direction either -1 or +1
* @return PageInterface|Collection The sibling item.
* @return PageInterface|false The sibling item.
*/
public function adjacentSibling($path, $direction = 1)
{
Expand All @@ -298,10 +298,10 @@ public function adjacentSibling($path, $direction = 1)
if (array_key_exists($path, $keys)) {
$index = $keys[$path] - $direction;

return isset($values[$index]) ? $this->offsetGet($values[$index]) : $this;
return isset($values[$index]) ? $this->offsetGet($values[$index]) : false;
}

return $this;
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public function isLast($path): bool;
* Gets the previous sibling based on current position.
*
* @param string $path
* @return PageInterface The previous item.
* @return PageInterface|false The previous item.
*/
public function prevSibling($path);

/**
* Gets the next sibling based on current position.
*
* @param string $path
* @return PageInterface The next item.
* @return PageInterface|false The next item.
*/
public function nextSibling($path);

Expand All @@ -144,7 +144,7 @@ public function nextSibling($path);
*
* @param string $path
* @param int $direction either -1 or +1
* @return PageInterface|PageCollectionInterface|false The sibling item.
* @return PageInterface|false The sibling item.
*/
public function adjacentSibling($path, $direction = 1);

Expand Down

0 comments on commit 5bb439c

Please sign in to comment.