Skip to content

Commit

Permalink
Protects against null root node, and ensures instance of Array_
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Apr 10, 2021
1 parent df0a140 commit 299938a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Analyzers/ConfigAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ public function removeNode($key)
if ($currentNode instanceof ArrayItem) {
$parent = $this->getParentKey($key);


if (mb_strlen($parent) > 0 && $this->hasNode($parent)) {
$parentNode = $this->nodeMapping[$parent];
$relativeKey = $this->getLastKeySegment($key);
Expand All @@ -495,21 +494,23 @@ public function removeNode($key)
$parentNode->value->items = $newItems;
}
} else {
$newItems = [];
if ($this->rootNode != null && $this->rootNode instanceof Array_) {
$newItems = [];

/** @var ArrayItem $valueItem */
foreach ($this->rootNode->items as $valueItem) {
$valueItemKey = $valueItem->key->value;
/** @var ArrayItem $valueItem */
foreach ($this->rootNode->items as $valueItem) {
$valueItemKey = $valueItem->key->value;

if ($valueItemKey === null || $valueItemKey !== $key) {
$newItems[] = $valueItem;
} else {
$foundNode = true;
if ($valueItemKey === null || $valueItemKey !== $key) {
$newItems[] = $valueItem;
} else {
$foundNode = true;
}
}
}

// Reassign the value items, without the node to remove.
$this->rootNode->items = $newItems;
// Reassign the value items, without the node to remove.
$this->rootNode->items = $newItems;
}
}
}

Expand Down

0 comments on commit 299938a

Please sign in to comment.