Rename node to key

This commit is contained in:
Andrea Marco Sartori 2022-11-13 17:10:31 +10:00
parent 183c8ba982
commit 8197d9b77b
3 changed files with 10 additions and 10 deletions

View File

@ -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] === '-';
}
/**

View File

@ -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;
}
/**

View File

@ -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
*/