Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void
$position = \count($this->rules[$propertyName]);

if ($sibling !== null) {
$iSiblingPos = \array_search($sibling, $this->rules[$propertyName], true);
if ($iSiblingPos !== false) {
$position = $iSiblingPos;
$siblingPosition = \array_search($sibling, $this->rules[$propertyName], true);
if ($siblingPosition !== false) {
$position = $siblingPosition;
$ruleToAdd->setPosition($sibling->getLineNo(), $sibling->getColNo() - 1);
}
}
if ($ruleToAdd->getLineNo() === 0 && $ruleToAdd->getColNo() === 0) {
//this node is added manually, give it the next best line
$rules = $this->getRules();
$pos = \count($rules);
if ($pos > 0) {
$last = $rules[$pos - 1];
$rulesCount = \count($rules);
if ($rulesCount > 0) {
$last = $rules[$rulesCount - 1];
$ruleToAdd->setPosition($last->getLineNo() + 1, 0);
}
}
Expand Down Expand Up @@ -176,6 +176,7 @@ public function getRules($searchPattern = null)
}
return $first->getLineNo() - $second->getLineNo();
});

return $result;
}

Expand Down Expand Up @@ -234,13 +235,13 @@ public function getRulesAssoc($searchPattern = null)
public function removeRule($searchPattern): void
{
if ($searchPattern instanceof Rule) {
$propertyName = $searchPattern->getRule();
if (!isset($this->rules[$propertyName])) {
$nameOfPropertyToRemove = $searchPattern->getRule();
if (!isset($this->rules[$nameOfPropertyToRemove])) {
return;
}
foreach ($this->rules[$propertyName] as $key => $rule) {
foreach ($this->rules[$nameOfPropertyToRemove] as $key => $rule) {
if ($rule === $searchPattern) {
unset($this->rules[$propertyName][$key]);
unset($this->rules[$nameOfPropertyToRemove][$key]);
}
}
} else {
Expand Down