diff --git a/src/Rules/Debug/DumpNativeTypeRule.php b/src/Rules/Debug/DumpNativeTypeRule.php index b71c550578..4f7fcdbcf6 100644 --- a/src/Rules/Debug/DumpNativeTypeRule.php +++ b/src/Rules/Debug/DumpNativeTypeRule.php @@ -35,7 +35,8 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (count($node->getArgs()) === 0) { + $args = $node->getArgs(); + if (count($args) === 0) { return []; } @@ -48,14 +49,17 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [ - RuleErrorBuilder::message( + $errors = []; + foreach ($args as $arg) { + $errors[] = RuleErrorBuilder::message( sprintf( 'Dumped type: %s', - $scope->getNativeType($node->getArgs()[0]->value)->describe(VerbosityLevel::precise()), + $scope->getNativeType($arg->value)->describe(VerbosityLevel::precise()), ), - )->nonIgnorable()->identifier('phpstan.dumpNativeType')->build(), - ]; + )->nonIgnorable()->identifier('phpstan.dumpNativeType')->build(); + } + + return $errors; } } diff --git a/src/Rules/Debug/DumpPhpDocTypeRule.php b/src/Rules/Debug/DumpPhpDocTypeRule.php index e91817d887..da5c74debe 100644 --- a/src/Rules/Debug/DumpPhpDocTypeRule.php +++ b/src/Rules/Debug/DumpPhpDocTypeRule.php @@ -35,7 +35,8 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (count($node->getArgs()) === 0) { + $args = $node->getArgs(); + if (count($args) === 0) { return []; } @@ -48,14 +49,17 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [ - RuleErrorBuilder::message( + $errors = []; + foreach ($args as $arg) { + $errors[] = RuleErrorBuilder::message( sprintf( 'Dumped type: %s', - $this->printer->print($scope->getType($node->getArgs()[0]->value)->toPhpDocNode()), + $this->printer->print($scope->getType($arg->value)->toPhpDocNode()), ), - )->nonIgnorable()->identifier('phpstan.dumpPhpDocType')->build(), - ]; + )->nonIgnorable()->identifier('phpstan.dumpPhpDocType')->build(); + } + + return $errors; } } diff --git a/src/Rules/Debug/DumpTypeRule.php b/src/Rules/Debug/DumpTypeRule.php index edbf5cb1ce..2cbd8adaa9 100644 --- a/src/Rules/Debug/DumpTypeRule.php +++ b/src/Rules/Debug/DumpTypeRule.php @@ -35,7 +35,8 @@ public function processNode(Node $node, Scope $scope): array return []; } - if (count($node->getArgs()) === 0) { + $args = $node->getArgs(); + if (count($args) === 0) { return []; } @@ -48,14 +49,17 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [ - RuleErrorBuilder::message( + $errors = []; + foreach ($args as $arg) { + $errors[] = RuleErrorBuilder::message( sprintf( 'Dumped type: %s', - $scope->getType($node->getArgs()[0]->value)->describe(VerbosityLevel::precise()), + $scope->getType($arg->value)->describe(VerbosityLevel::precise()), ), - )->nonIgnorable()->identifier('phpstan.dumpType')->build(), - ]; + )->nonIgnorable()->identifier('phpstan.dumpType')->build(); + } + + return $errors; } } diff --git a/src/dumpType.php b/src/dumpType.php index 64da7d525b..5fe276ceaf 100644 --- a/src/dumpType.php +++ b/src/dumpType.php @@ -5,11 +5,12 @@ /** * @phpstan-pure * @param mixed $value + * @param mixed $values * @return mixed * * @throws void */ -function dumpType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found +function dumpType($value, ...$values) // phpcs:ignore Squiz.Functions.GlobalFunction.Found { return null; } @@ -17,11 +18,12 @@ function dumpType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found /** * @phpstan-pure * @param mixed $value + * @param mixed $values * @return mixed * * @throws void */ -function dumpNativeType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found +function dumpNativeType($value, ...$values) // phpcs:ignore Squiz.Functions.GlobalFunction.Found { return null; } @@ -29,11 +31,12 @@ function dumpNativeType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.F /** * @phpstan-pure * @param mixed $value + * @param mixed $values * @return mixed * * @throws void */ -function dumpPhpDocType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found +function dumpPhpDocType($value, ...$values) // phpcs:ignore Squiz.Functions.GlobalFunction.Found { return null; } diff --git a/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php index 71aba72e45..4df1299af3 100644 --- a/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php @@ -27,6 +27,14 @@ public function testRule(): void 'Dumped type: array', 12, ], + [ + 'Dumped type: non-empty-array', + 14, + ], + [ + 'Dumped type: array', + 14, + ], ]); } diff --git a/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php index 8b137b1611..d5cc525ef1 100644 --- a/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php @@ -100,6 +100,14 @@ public function testRuleSymbols(): void 'Dumped type: T', 36, ], + [ + 'Dumped type: array{1: 1}', + 41, + ], + [ + 'Dumped type: array{2: 2}', + 41, + ], ]); } diff --git a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php index fb4c489dea..acc55c027b 100644 --- a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php @@ -50,6 +50,20 @@ public function testRuleInUse(): void ]); } + public function testRuleWithMultipleVars(): void + { + $this->analyse([__DIR__ . '/data/dump-type-variadic.php'], [ + [ + 'Dumped type: non-empty-array', + 10, + ], + [ + 'Dumped type: array', + 10, + ], + ]); + } + public function testBug7803(): void { $this->analyse([__DIR__ . '/data/bug-7803.php'], [ diff --git a/tests/PHPStan/Rules/Debug/data/dump-native-type.php b/tests/PHPStan/Rules/Debug/data/dump-native-type.php index e475cf1aef..ec3cb6ac04 100644 --- a/tests/PHPStan/Rules/Debug/data/dump-native-type.php +++ b/tests/PHPStan/Rules/Debug/data/dump-native-type.php @@ -10,4 +10,6 @@ function (array $a, array $b) { dumpNativeType($a); dumpNativeType($b); + + dumpNativeType($a, $b); }; diff --git a/tests/PHPStan/Rules/Debug/data/dump-phpdoc-type.php b/tests/PHPStan/Rules/Debug/data/dump-phpdoc-type.php index 2b5c9c1d40..760653e5c6 100644 --- a/tests/PHPStan/Rules/Debug/data/dump-phpdoc-type.php +++ b/tests/PHPStan/Rules/Debug/data/dump-phpdoc-type.php @@ -37,3 +37,5 @@ function id($value) return $value; } + +dumpPhpDocType([1 => 1], [2 => 2]); diff --git a/tests/PHPStan/Rules/Debug/data/dump-type-variadic.php b/tests/PHPStan/Rules/Debug/data/dump-type-variadic.php new file mode 100644 index 0000000000..5bfca23640 --- /dev/null +++ b/tests/PHPStan/Rules/Debug/data/dump-type-variadic.php @@ -0,0 +1,11 @@ +analyse([__DIR__ . '/data/bug-8936.php'], []); } + public function testDumpFunctions(): void + { + $this->analyse([__DIR__ . '/data/dump-functions.php'], [ + [ + 'Function PHPStan\dumpType invoked with 0 parameters, at least 1 required.', + 13, + ], + [ + 'Function PHPStan\dumpNativeType invoked with 0 parameters, at least 1 required.', + 14, + ], + [ + 'Function PHPStan\dumpPhpDocType invoked with 0 parameters, at least 1 required.', + 15, + ], + ]); + } + public function testBug14012(): void { $this->checkExplicitMixed = true; diff --git a/tests/PHPStan/Rules/Functions/data/dump-functions.php b/tests/PHPStan/Rules/Functions/data/dump-functions.php new file mode 100644 index 0000000000..826b65d4b1 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/dump-functions.php @@ -0,0 +1,21 @@ +