From 9a0a1610cb81ca6a4f5c8def0831d9a20072b670 Mon Sep 17 00:00:00 2001 From: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:57:15 +0000 Subject: [PATCH] Include argument index in `dumpType` message to preserve argument order - When multiple arguments are passed to `dumpType()`, `dumpNativeType()`, or `dumpPhpDocType()`, messages now include `#N` (e.g. "Dumped type #1: int") to maintain stable argument ordering through the alphabetical error sort - Single-argument calls retain the original "Dumped type: ..." format - Fixed all three dump rules: DumpTypeRule, DumpNativeTypeRule, DumpPhpDocTypeRule - Updated existing multi-arg test expectations to match new format --- src/Rules/Debug/DumpNativeTypeRule.php | 6 ++++-- src/Rules/Debug/DumpPhpDocTypeRule.php | 6 ++++-- src/Rules/Debug/DumpTypeRule.php | 6 ++++-- .../Rules/Debug/DumpNativeTypeRuleTest.php | 18 ++++++++++++++++-- .../Rules/Debug/DumpPhpDocTypeRuleTest.php | 18 ++++++++++++++++-- tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php | 18 ++++++++++++++++-- .../Rules/Debug/data/bug-14508-native.php | 10 ++++++++++ .../Rules/Debug/data/bug-14508-phpdoc.php | 10 ++++++++++ tests/PHPStan/Rules/Debug/data/bug-14508.php | 10 ++++++++++ 9 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 tests/PHPStan/Rules/Debug/data/bug-14508-native.php create mode 100644 tests/PHPStan/Rules/Debug/data/bug-14508-phpdoc.php create mode 100644 tests/PHPStan/Rules/Debug/data/bug-14508.php diff --git a/src/Rules/Debug/DumpNativeTypeRule.php b/src/Rules/Debug/DumpNativeTypeRule.php index 4f7fcdbcf60..b20410c2eb7 100644 --- a/src/Rules/Debug/DumpNativeTypeRule.php +++ b/src/Rules/Debug/DumpNativeTypeRule.php @@ -49,11 +49,13 @@ public function processNode(Node $node, Scope $scope): array return []; } + $multipleArgs = count($args) > 1; $errors = []; - foreach ($args as $arg) { + foreach ($args as $i => $arg) { $errors[] = RuleErrorBuilder::message( sprintf( - 'Dumped type: %s', + $multipleArgs ? 'Dumped type #%d: %s' : 'Dumped type: %2$s', + $i + 1, $scope->getNativeType($arg->value)->describe(VerbosityLevel::precise()), ), )->nonIgnorable()->identifier('phpstan.dumpNativeType')->build(); diff --git a/src/Rules/Debug/DumpPhpDocTypeRule.php b/src/Rules/Debug/DumpPhpDocTypeRule.php index da5c74debe1..c764f12bb8f 100644 --- a/src/Rules/Debug/DumpPhpDocTypeRule.php +++ b/src/Rules/Debug/DumpPhpDocTypeRule.php @@ -49,11 +49,13 @@ public function processNode(Node $node, Scope $scope): array return []; } + $multipleArgs = count($args) > 1; $errors = []; - foreach ($args as $arg) { + foreach ($args as $i => $arg) { $errors[] = RuleErrorBuilder::message( sprintf( - 'Dumped type: %s', + $multipleArgs ? 'Dumped type #%d: %s' : 'Dumped type: %2$s', + $i + 1, $this->printer->print($scope->getType($arg->value)->toPhpDocNode()), ), )->nonIgnorable()->identifier('phpstan.dumpPhpDocType')->build(); diff --git a/src/Rules/Debug/DumpTypeRule.php b/src/Rules/Debug/DumpTypeRule.php index 2cbd8adaa97..3c2f0128541 100644 --- a/src/Rules/Debug/DumpTypeRule.php +++ b/src/Rules/Debug/DumpTypeRule.php @@ -49,11 +49,13 @@ public function processNode(Node $node, Scope $scope): array return []; } + $multipleArgs = count($args) > 1; $errors = []; - foreach ($args as $arg) { + foreach ($args as $i => $arg) { $errors[] = RuleErrorBuilder::message( sprintf( - 'Dumped type: %s', + $multipleArgs ? 'Dumped type #%d: %s' : 'Dumped type: %2$s', + $i + 1, $scope->getType($arg->value)->describe(VerbosityLevel::precise()), ), )->nonIgnorable()->identifier('phpstan.dumpType')->build(); diff --git a/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php index 4df1299af35..bfdd614b081 100644 --- a/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php @@ -28,14 +28,28 @@ public function testRule(): void 12, ], [ - 'Dumped type: non-empty-array', + 'Dumped type #1: non-empty-array', 14, ], [ - 'Dumped type: array', + 'Dumped type #2: array', 14, ], ]); } + public function testBug14508(): void + { + $this->analyse([__DIR__ . '/data/bug-14508-native.php'], [ + [ + 'Dumped type #1: int', + 10, + ], + [ + 'Dumped type #2: bool', + 10, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php index d5cc525ef1b..256ceac886c 100644 --- a/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php @@ -101,14 +101,28 @@ public function testRuleSymbols(): void 36, ], [ - 'Dumped type: array{1: 1}', + 'Dumped type #1: array{1: 1}', 41, ], [ - 'Dumped type: array{2: 2}', + 'Dumped type #2: array{2: 2}', 41, ], ]); } + public function testBug14508(): void + { + $this->analyse([__DIR__ . '/data/bug-14508-phpdoc.php'], [ + [ + 'Dumped type #1: int<0, 100>', + 10, + ], + [ + 'Dumped type #2: bool', + 10, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php index acc55c027b7..169c5f73e24 100644 --- a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php @@ -54,11 +54,11 @@ public function testRuleWithMultipleVars(): void { $this->analyse([__DIR__ . '/data/dump-type-variadic.php'], [ [ - 'Dumped type: non-empty-array', + 'Dumped type #1: non-empty-array', 10, ], [ - 'Dumped type: array', + 'Dumped type #2: array', 10, ], ]); @@ -116,4 +116,18 @@ public function testBug11179NoNamespace(): void ]); } + public function testBug14508(): void + { + $this->analyse([__DIR__ . '/data/bug-14508.php'], [ + [ + 'Dumped type #1: int<0, 100>', + 10, + ], + [ + 'Dumped type #2: bool', + 10, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Debug/data/bug-14508-native.php b/tests/PHPStan/Rules/Debug/data/bug-14508-native.php new file mode 100644 index 00000000000..c4251ed1511 --- /dev/null +++ b/tests/PHPStan/Rules/Debug/data/bug-14508-native.php @@ -0,0 +1,10 @@ +