Skip to content

Commit

Permalink
Make PHPStan\dumpType pure
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard van Velzen authored and ondrejmirtes committed Aug 30, 2022
1 parent f8f6e2a commit ad8335d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function processNode(Node $node, Scope $scope): array
}

if (in_array($function->getName(), [
'PHPStan\\dumpType',
'PHPStan\\Testing\\assertType',
'PHPStan\\Testing\\assertNativeType',
'PHPStan\\Testing\\assertVariableCertainty',
Expand Down
7 changes: 6 additions & 1 deletion src/dumpType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
namespace PHPStan;

/**
* @phpstan-pure
* @param mixed $value
* @return mixed
*
* @throws void
*/
function dumpType($value): void // phpcs:ignore Squiz.Functions.GlobalFunction.Found
function dumpType($value) // phpcs:ignore Squiz.Functions.GlobalFunction.Found
{
return null;
}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ public function testRuleInUse(): void
]);
}

public function testBug7803(): void
{
$this->analyse([__DIR__ . '/data/bug-7803.php'], [
[
'Dumped type: int<4, max>',
11,
],
[
'Dumped type: non-empty-array<int, string>',
12,
],
[
'Dumped type: int<4, max>',
13,
],
]);
}

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

namespace Bug7803;

use function PHPStan\dumpType;

/** @param array<int, string> $headers */
function headers(array $headers): void
{
if (count($headers) >= 4) {
dumpType(count($headers));
dumpType($headers);
dumpType(count($headers));
}
}

0 comments on commit ad8335d

Please sign in to comment.