Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/Rules/Debug/DumpNativeTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/Rules/Debug/DumpPhpDocTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/Rules/Debug/DumpTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions tests/PHPStan/Rules/Debug/DumpNativeTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
}

}
18 changes: 16 additions & 2 deletions tests/PHPStan/Rules/Debug/DumpPhpDocTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
}

}
18 changes: 16 additions & 2 deletions tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
Expand Down Expand Up @@ -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,
],
]);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Debug/data/bug-14508-native.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace Bug14508Native;

use function PHPStan\dumpNativeType;

$bool_set_before = (bool) random_int(0, 1);
$int_set_after = random_int(0, 100);

dumpNativeType($int_set_after, $bool_set_before);
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Debug/data/bug-14508-phpdoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace Bug14508PhpDoc;

use function PHPStan\dumpPhpDocType;

$bool_set_before = (bool) random_int(0, 1);
$int_set_after = random_int(0, 100);

dumpPhpDocType($int_set_after, $bool_set_before);
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Debug/data/bug-14508.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace Bug14508;

use function PHPStan\dumpType;

$bool_set_before = (bool) random_int(0, 1);
$int_set_after = random_int(0, 100);

dumpType($int_set_after, $bool_set_before);
Loading