Skip to content

Commit 4086767

Browse files
authored
[TASK] Update RuleSet::comparePositionable to use new methods (#1283)
`getLineNo` and `getColNo` are deprecated. When the titled method was extracted, use of the above-mentioned methods was retained to ease backporting and transition to their replacement counterparts: `getLineNumber` and `getColumnNumber`, which differ by returning `null` in the case of 'not set'. This replaces all instances of calls to `getColNo`. Part of #974
1 parent 43a3735 commit 4086767

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/RuleSet/RuleSet.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,33 @@ protected function renderRules(OutputFormat $outputFormat): string
326326

327327
/**
328328
* @return int negative if `$first` is before `$second`; zero if they have the same position; positive otherwise
329+
*
330+
* @throws \UnexpectedValueException if either argument does not have a valid position, which should never happen
329331
*/
330332
private static function comparePositionable(Positionable $first, Positionable $second): int
331333
{
332-
if ($first->getLineNo() === $second->getLineNo()) {
333-
return $first->getColNo() - $second->getColNo();
334+
$firstsLineNumber = $first->getLineNumber();
335+
$secondsLineNumber = $second->getLineNumber();
336+
if (!\is_int($firstsLineNumber) || !\is_int($secondsLineNumber)) {
337+
throw new \UnexpectedValueException(
338+
'A Rule without a line number was passed to comparePositionable',
339+
1750637683
340+
);
334341
}
335-
return $first->getLineNo() - $second->getLineNo();
342+
343+
if ($firstsLineNumber === $secondsLineNumber) {
344+
$firstsColumnNumber = $first->getColumnNumber();
345+
$secondsColumnNumber = $second->getColumnNumber();
346+
if (!\is_int($firstsColumnNumber) || !\is_int($secondsColumnNumber)) {
347+
throw new \UnexpectedValueException(
348+
'A Rule without a column number was passed to comparePositionable',
349+
1750637761
350+
);
351+
}
352+
return $firstsColumnNumber - $secondsColumnNumber;
353+
}
354+
355+
return $firstsLineNumber - $secondsLineNumber;
336356
}
337357

338358
private function hasRule(Rule $rule): bool

0 commit comments

Comments
 (0)