Skip to content

Commit 5195842

Browse files
committed
Preserve reflection parameter query return types on PHP 7.4
1 parent a83b91f commit 5195842

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎stubs/ReflectionParameter.stub‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ class ReflectionParameter
1010
}
1111

1212
/**
13+
* @return bool
1314
* @phpstan-assert-if-true !null $this->getType()
1415
*/
1516
public function hasType(): bool
1617
{
1718
}
1819

1920
/**
21+
* @return bool
2022
* @throws void
2123
*/
2224
public function isOptional(): bool
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PHPStan\Testing\TypeInferenceTestCase;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
8+
class ReflectionParameterPhp7Test extends TypeInferenceTestCase
9+
{
10+
11+
public static function dataFileAsserts(): iterable
12+
{
13+
yield from self::gatherAssertTypes(__DIR__ . '/nsrt/reflection-parameter-type-catch.php');
14+
}
15+
16+
/**
17+
* @param mixed ...$args
18+
*/
19+
#[DataProvider('dataFileAsserts')]
20+
public function testFileAsserts(string $assertType, string $file, ...$args): void
21+
{
22+
$this->assertFileAsserts($assertType, $file, ...$args);
23+
}
24+
25+
public static function getAdditionalConfigFiles(): array
26+
{
27+
return [
28+
__DIR__ . '/nodeScopeResolverPhp7.neon',
29+
];
30+
}
31+
32+
}

‎tests/PHPStan/Analyser/nsrt/reflection-parameter-type-catch.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ function checkOptional(\ReflectionParameter $parameter): void
4949

5050
assertType('bool', $optional);
5151
}
52+
53+
function checkHasType(\ReflectionParameter $parameter): void
54+
{
55+
assertType('bool', $parameter->hasType());
56+
}

0 commit comments

Comments
 (0)