Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return false instead of Collection if adjacent item not found #3397

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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