Skip to content

Commit ce28abd

Browse files
authored
is_resource: adjust type specification for truthy context only
1 parent e06dbaa commit ce28abd

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

stubs/typeCheckingFunctions.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function is_long(mixed $value): bool
105105
}
106106

107107
/**
108-
* @phpstan-assert-if-true resource $value
108+
* @phpstan-assert-if-true =resource $value
109109
* @return bool
110110
*/
111111
function is_resource(mixed $value): bool

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public function dataFileAsserts(): iterable
143143
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-7823.php');
144144
}
145145

146+
yield from $this->gatherAssertTypes(__DIR__ . '/../Analyser/data/is-resource-specified.php');
147+
146148
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-7954.php');
147149
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Comparison/data/docblock-assert-equality.php');
148150
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Properties/data/bug-7839.php');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use function PHPStan\Testing\assertType;
4+
5+
$resource = fopen('php://memory', 'r');
6+
7+
if (is_resource($resource)) {
8+
assertType('resource', $resource);
9+
} else {
10+
assertType('resource|false', $resource); // can be closed resource
11+
}

tests/PHPStan/Rules/Comparison/data/check-type-function-call.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,3 +967,12 @@ function checkSuperGlobals(): void
967967
if (is_int($k)) {}
968968
}
969969
}
970+
971+
/**
972+
* @param resource $resource
973+
*/
974+
function checkClosedResource($resource): void {
975+
if (!is_resource($resource)) {
976+
977+
}
978+
}

0 commit comments

Comments
 (0)