Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5f866b

Browse files
VincentLangletondrejmirtes
authored andcommitted
Improve is_resource inference
1 parent a3d50de commit b5f866b

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

‎stubs/typeCheckingFunctions.stub‎

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

107107
/**
108108
* @phpstan-assert-if-true =resource $value
109-
* @return bool
109+
* @return ($value is resource ? bool : false)
110110
*/
111111
function is_resource(mixed $value): bool
112112
{

‎tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,12 @@ public function testBug12087c(): void
10941094
]);
10951095
}
10961096

1097+
public function testBug10394(): void
1098+
{
1099+
$this->treatPhpDocTypesAsCertain = true;
1100+
$this->analyse([__DIR__ . '/data/bug-10394.php'], []);
1101+
}
1102+
10971103
public function testBug9666(): void
10981104
{
10991105
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bug10394;
4+
5+
class SomeClass
6+
{
7+
private int $integer = 0;
8+
9+
public function __construct()
10+
{
11+
// try commenting this out!
12+
$this->integer = 45;
13+
14+
if (is_resource($this->integer)) {
15+
throw new \Exception('A resource??');
16+
}
17+
}
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /