From 5bb439cb17c1a6d4ea4673dda44ffec62d90727b Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Tue, 6 Jul 2021 17:29:16 +0300 Subject: [PATCH] Return false instead of collection if adjacent item not found #3396 --- system/src/Grav/Common/Page/Collection.php | 10 +++++----- .../Common/Page/Interfaces/PageCollectionInterface.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php index 139a58bc54..9cf76c043f 100644 --- a/system/src/Grav/Common/Page/Collection.php +++ b/system/src/Grav/Common/Page/Collection.php @@ -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) { @@ -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) { @@ -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) { @@ -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; } /** diff --git a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php index 50029118fb..e861a85e60 100644 --- a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php +++ b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php @@ -127,7 +127,7 @@ 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); @@ -135,7 +135,7 @@ 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); @@ -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);