Skip to content

Commit afdca11

Browse files
authored
[CLEANUP] Extract method RuleSet::comparePositionable (#1272)
As well as being used with `usort()`, it may have other uses. The deprecated `getLineNo()` and `getColNo()` are still used for now. Replacing these will be done separately. Relates to #974.
1 parent a51fc82 commit afdca11

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/RuleSet/RuleSet.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,7 @@ public function getRules(?string $searchPattern = null): array
173173
$result = \array_merge($result, $rules);
174174
}
175175
}
176-
\usort($result, static function (Rule $first, Rule $second): int {
177-
if ($first->getLineNo() === $second->getLineNo()) {
178-
return $first->getColNo() - $second->getColNo();
179-
}
180-
return $first->getLineNo() - $second->getLineNo();
181-
});
176+
\usort($result, [self::class, 'comparePositionable']);
182177

183178
return $result;
184179
}
@@ -299,4 +294,15 @@ protected function renderRules(OutputFormat $outputFormat): string
299294

300295
return $formatter->removeLastSemicolon($result);
301296
}
297+
298+
/**
299+
* @return int negative if `$first` is before `$second`; zero if they have the same position; positive otherwise
300+
*/
301+
private static function comparePositionable(Positionable $first, Positionable $second): int
302+
{
303+
if ($first->getLineNo() === $second->getLineNo()) {
304+
return $first->getColNo() - $second->getColNo();
305+
}
306+
return $first->getLineNo() - $second->getLineNo();
307+
}
302308
}

0 commit comments

Comments
 (0)