Skip to content

Commit 28972ee

Browse files
committed
Use comparePositionable()
1 parent 7642f68 commit 28972ee

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/RuleSet/RuleSet.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void
104104
$position = \count($this->rules[$propertyName]);
105105

106106
if ($sibling !== null) {
107-
$siblingLineNumber = $sibling->getLineNumber();
108-
$siblingColumnNumber = $sibling->getColumnNumber();
109107
$siblingIsInSet = false;
110108
$siblingPosition = \array_search($sibling, $this->rules[$propertyName], true);
111109
if ($siblingPosition !== false) {
@@ -115,17 +113,15 @@ public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void
115113
// Maintain ordering within `$this->rules[$propertyName]`
116114
// by inserting before first `Rule` with a same-or-later position than the sibling.
117115
foreach ($this->rules[$propertyName] as $index => $rule) {
118-
if (
119-
$rule->getLineNumber() > $siblingLineNumber ||
120-
$rule->getLineNumber() === $siblingLineNumber &&
121-
$rule->getColumnNumber() >= $siblingColumnNumber
122-
) {
116+
if (self::comparePositionable($rule, $sibling) >= 0) {
123117
$position = $index;
124118
break;
125119
}
126120
}
127121
}
128122
if ($siblingIsInSet) {
123+
$siblingLineNumber = $sibling->getLineNumber();
124+
$siblingColumnNumber = $sibling->getColumnNumber();
129125
// Increment column number of all existing rules on same line, starting at sibling
130126
foreach ($this->rules as $rulesForAProperty) {
131127
foreach ($rulesForAProperty as $rule) {

0 commit comments

Comments
 (0)