Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/Rules/Debug/DumpNativeTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand All @@ -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;
}

}
16 changes: 10 additions & 6 deletions src/Rules/Debug/DumpPhpDocTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand All @@ -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;
}

}
16 changes: 10 additions & 6 deletions src/Rules/Debug/DumpTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand All @@ -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;
}

}
6 changes: 3 additions & 3 deletions src/dumpType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @throws void
*/
function dumpType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
function dumpType(...$value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
Comment thread
VincentLanglet marked this conversation as resolved.
Outdated
{
return null;
}
Expand All @@ -21,7 +21,7 @@ function dumpType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
*
* @throws void
*/
function dumpNativeType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
function dumpNativeType(...$value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
{
return null;
}
Expand All @@ -33,7 +33,7 @@ function dumpNativeType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.F
*
* @throws void
*/
function dumpPhpDocType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
function dumpPhpDocType(...$value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
{
return null;
}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function testRule(): void
'Dumped type: array',
12,
],
[
'Dumped type: non-empty-array',
14,
],
[
'Dumped type: array',
14,
],
]);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public function testRuleSymbols(): void
'Dumped type: T',
36,
],
[
'Dumped type: array{1: 1}',
41,
],
[
'Dumped type: array{2: 2}',
41,
],
]);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], [
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/Debug/data/dump-native-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ function (array $a, array $b) {

dumpNativeType($a);
dumpNativeType($b);

dumpNativeType($a, $b);
};
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/Debug/data/dump-phpdoc-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ function id($value)

return $value;
}

dumpPhpDocType([1 => 1], [2 => 2]);
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Debug/data/dump-type-variadic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PHPStan;

function (array $a, array $b) {
if ($a === []) {
return;
}

dumpType($a, $b);
};
Loading