From 8197d9b77b13161b15782ff7beb39299fb0c8965 Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Sun, 13 Nov 2022 17:10:31 +1000 Subject: [PATCH] Rename node to key --- src/Pointers/Pointer.php | 10 +++++----- src/Pointers/Pointers.php | 6 +++--- src/State.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Pointers/Pointer.php b/src/Pointers/Pointer.php index 11e98d8..834fe13 100644 --- a/src/Pointers/Pointer.php +++ b/src/Pointers/Pointer.php @@ -70,23 +70,23 @@ class Pointer implements ArrayAccess, Stringable } /** - * Determine whether the reference token at the given depth matches the provided node + * Determine whether the reference token at the given depth matches the provided key * * @param int $depth - * @param mixed $node + * @param mixed $key * @return bool */ - public function depthMatchesNode(int $depth, mixed $node): bool + public function depthMatchesKey(int $depth, mixed $key): bool { if (!isset($this->referenceTokens[$depth])) { return false; } - if ($this->referenceTokens[$depth] === (string) $node) { + if ($this->referenceTokens[$depth] === (string) $key) { return true; } - return is_int($node) && $this->referenceTokens[$depth] === '-'; + return is_int($key) && $this->referenceTokens[$depth] === '-'; } /** diff --git a/src/Pointers/Pointers.php b/src/Pointers/Pointers.php index 90bf207..70163f5 100644 --- a/src/Pointers/Pointers.php +++ b/src/Pointers/Pointers.php @@ -54,8 +54,8 @@ class Pointers implements Countable $pointers = []; foreach ($this->pointers as $pointer) { - foreach ($tree as $depth => $node) { - if (!$pointer->depthMatchesNode($depth, $node)) { + foreach ($tree as $depth => $key) { + if (!$pointer->depthMatchesKey($depth, $key)) { continue 2; } elseif (!isset($pointers[$depth])) { $pointers[$depth] = $pointer; @@ -63,7 +63,7 @@ class Pointers implements Countable } } - return end($pointers) ?: $this->defaultPointer; + return end($pointers) ?: $this->pointers[0] ?? $this->defaultPointer; } /** diff --git a/src/State.php b/src/State.php index 04a61c0..b482d4c 100644 --- a/src/State.php +++ b/src/State.php @@ -89,7 +89,7 @@ class State } /** - * Retrieve the current node of the JSON tree + * Retrieve the current key of the JSON tree * * @return string */ @@ -284,7 +284,7 @@ class State } /** - * Determine whether the currently parsed node is an object + * Determine whether the current position is within an object * * @return bool */