From 111f67bb96d4565e7c52b4055572128d8d51210f Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 21 Jun 2024 17:45:17 +0200 Subject: [PATCH] Simplify keys call (#51876) --- src/Illuminate/Collections/Collection.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 8d58dc5d1202..207022e8b3f4 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -1129,13 +1129,13 @@ public function before($value, $strict = false) return null; } - $position = $this->keys()->search($key); + $position = ($keys = $this->keys())->search($key); if ($position === 0) { return null; } - return $this->get($this->keys()->get($position - 1)); + return $this->get($keys->get($position - 1)); } /** @@ -1153,13 +1153,13 @@ public function after($value, $strict = false) return null; } - $position = $this->keys()->search($key); + $position = ($keys = $this->keys())->search($key); - if ($position === $this->keys()->count() - 1) { + if ($position === $keys->count() - 1) { return null; } - return $this->get($this->keys()->get($position + 1)); + return $this->get($keys->get($position + 1)); } /**