Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion stubs/typeCheckingFunctions.stub
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function is_long(mixed $value): bool
}

/**
* @phpstan-assert-if-true resource $value
* @phpstan-assert-if-true =resource $value
* @return bool
*/
function is_resource(mixed $value): bool
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-7823.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/../Analyser/data/is-resource-specified.php');

yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-7954.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Comparison/data/docblock-assert-equality.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Properties/data/bug-7839.php');
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Analyser/data/is-resource-specified.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use function PHPStan\Testing\assertType;

$resource = fopen('php://memory', 'r');

if (is_resource($resource)) {
assertType('resource', $resource);
} else {
assertType('resource|false', $resource); // can be closed resource
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function () {
throw new \Exception();
}

if (!is_resource($resource)) {
$resource = fopen('php://memory', 'r');
if ($resource === false) {
throw new \Exception();
}

Expand Down
Loading