Skip to content

Commit 8c3abf4

Browse files
authoredMar 3, 2025··
Sort tips in transitively dead groups (#146)
1 parent e3ef123 commit 8c3abf4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed
 

‎src/Rule/DeadCodeRule.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,13 @@ private function buildError(array $blackMembersGroup): IdentifierRuleError
587587
'transitive' => false,
588588
];
589589

590+
$tips = [];
591+
590592
foreach (array_slice($blackMembersGroup, 1) as $transitivelyDeadMember) {
591593
$transitiveDeadMemberRef = $transitivelyDeadMember->getMember()->toHumanString();
592594
$exclusionMessage = $transitivelyDeadMember->getExclusionMessage();
593595

594-
$builder->addTip("Thus $transitiveDeadMemberRef is transitively also unused{$exclusionMessage}");
595-
596+
$tips[$transitiveDeadMemberRef] = "Thus $transitiveDeadMemberRef is transitively also unused{$exclusionMessage}";
596597
$metadata[$transitiveDeadMemberRef] = [
597598
'file' => $transitivelyDeadMember->getFile(),
598599
'line' => $transitivelyDeadMember->getLine(),
@@ -602,6 +603,12 @@ private function buildError(array $blackMembersGroup): IdentifierRuleError
602603

603604
$builder->metadata($metadata);
604605

606+
ksort($tips);
607+
608+
foreach ($tips as $tip) {
609+
$builder->addTip($tip);
610+
}
611+
605612
return $builder->build();
606613
}
607614

‎tests/Rule/DeadCodeRuleTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,16 @@ public static function provideGroupingFiles(): iterable
242242
[
243243
'Unused Grouping\Example::boo',
244244
29,
245+
"• Thus Grouping\Example::TRANSITIVELY_UNUSED_CONST is transitively also unused\n" .
245246
"• Thus Grouping\Example::bag is transitively also unused\n" .
246-
"• Thus Grouping\Example::bar is transitively also unused\n" .
247-
'• Thus Grouping\Example::TRANSITIVELY_UNUSED_CONST is transitively also unused',
247+
'• Thus Grouping\Example::bar is transitively also unused',
248248
],
249249
[
250250
'Unused Grouping\Example::foo',
251251
23,
252-
"• Thus Grouping\Example::bar is transitively also unused\n" .
252+
"• Thus Grouping\Example::TRANSITIVELY_UNUSED_CONST is transitively also unused\n" .
253253
"• Thus Grouping\Example::bag is transitively also unused\n" .
254-
'• Thus Grouping\Example::TRANSITIVELY_UNUSED_CONST is transitively also unused',
254+
'• Thus Grouping\Example::bar is transitively also unused',
255255
],
256256
[
257257
'Unused Grouping\Example::recur',

0 commit comments

Comments
 (0)