Skip to content

Commit 5d4761c

Browse files
jiripudilondrejmirtes
authored andcommitted
is_a(): add some more type-specifier tests
1 parent b4e4a29 commit 5d4761c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9981,6 +9981,11 @@ public function dataIsNumeric(): array
99819981
return $this->gatherAssertTypes(__DIR__ . '/data/is-numeric.php');
99829982
}
99839983

9984+
public function dataIsA(): array
9985+
{
9986+
return $this->gatherAssertTypes(__DIR__ . '/data/is-a.php');
9987+
}
9988+
99849989
public function dataBug3142(): array
99859990
{
99869991
return $this->gatherAssertTypes(__DIR__ . '/data/bug-3142.php');
@@ -10537,6 +10542,7 @@ private function gatherAssertTypes(string $file): array
1053710542
* @dataProvider dataExtDs
1053810543
* @dataProvider dataArrowFunctionReturnTypeInference
1053910544
* @dataProvider dataIsNumeric
10545+
* @dataProvider dataIsA
1054010546
* @dataProvider dataBug3142
1054110547
* @dataProvider dataArrayShapeKeysStrings
1054210548
* @dataProvider dataBug1216
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
function (object $foo) {
4+
if (is_a($foo, Foo::class)) {
5+
\PHPStan\Analyser\assertType('Foo', $foo);
6+
}
7+
};
8+
9+
function (object $foo) {
10+
/** @var class-string<Foo> $fooClassString */
11+
$fooClassString = 'Foo';
12+
13+
if (is_a($foo, $fooClassString)) {
14+
\PHPStan\Analyser\assertType('Foo', $foo);
15+
}
16+
};
17+
18+
function (string $foo) {
19+
if (is_a($foo, Foo::class, true)) {
20+
\PHPStan\Analyser\assertType('class-string<Foo>', $foo);
21+
}
22+
};
23+
24+
function (string $foo, string $someString) {
25+
if (is_a($foo, $someString, true)) {
26+
\PHPStan\Analyser\assertType('class-string<object>', $foo);
27+
}
28+
};

0 commit comments

Comments
 (0)