Prevent duplicate/overwritten keys
This commit is contained in:
@@ -15,8 +15,16 @@ class ObjectNode extends Node implements CollapsibleNode
|
||||
$this->properties[$key] = $value;
|
||||
}
|
||||
|
||||
public function hasKey(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->properties);
|
||||
}
|
||||
|
||||
public function rename(string $key, string $newKey)
|
||||
{
|
||||
if (array_key_exists($newKey, $this->properties)) {
|
||||
throw new \Exception("Key {$newKey} already exists");
|
||||
}
|
||||
$renamed = [];
|
||||
foreach ($this->properties as $k=>$v) {
|
||||
$renamed[($k==$key)?$newKey:$k] = $v;
|
||||
|
||||
Reference in New Issue
Block a user