mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 13:08:16 +01:00
Rename node to key
This commit is contained in:
parent
183c8ba982
commit
8197d9b77b
@ -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] === '-';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user