diff --git a/stubs/Php80.phpstub b/stubs/Php80.phpstub index 5d3c9fcf4cd..c9da1534a03 100644 --- a/stubs/Php80.phpstub +++ b/stubs/Php80.phpstub @@ -89,14 +89,18 @@ class ReflectionClass implements Reflector { public function getDocComment(): string|false {} /** - * @param ReflectionClass|class-string $class + * @template J as object + * @param self|class-string $class + * @psalm-assert-if-true self $this * * @psalm-pure */ public function isSubclassOf(self|string $class): bool {} /** - * @param self|class-string $interface + * @template J as object + * @param self|interface-string $interface + * @psalm-assert-if-true self $this * * @psalm-pure */ diff --git a/stubs/Reflection.phpstub b/stubs/Reflection.phpstub index 02bfa3859c5..b44d37620e4 100644 --- a/stubs/Reflection.phpstub +++ b/stubs/Reflection.phpstub @@ -222,7 +222,9 @@ class ReflectionClass implements Reflector { public function getParentClass() {} /** - * @param ReflectionClass|class-string $class + * @template J as object + * @param self|class-string $class + * @psalm-assert-if-true self $this * * @psalm-pure */ @@ -245,7 +247,9 @@ class ReflectionClass implements Reflector { public function isIterable(): bool {} /** - * @param self|class-string $interface + * @template J as object + * @param self|interface-string $interface + * @psalm-assert-if-true self $this * * @psalm-pure */ diff --git a/tests/ReflectionTest.php b/tests/ReflectionTest.php new file mode 100644 index 00000000000..b8e7bb998a4 --- /dev/null +++ b/tests/ReflectionTest.php @@ -0,0 +1,36 @@ + [ + 'code' => <<<'PHP' + isSubclassOf(Iterator::class)) { + throw new Exception(); + } + PHP, + 'assertions' => ['$a===' => 'ReflectionClass'], + ]; + yield 'ReflectionClass::implementsInterface' => [ + 'code' => <<<'PHP' + implementsInterface(Iterator::class)) { + throw new Exception(); + } + PHP, + 'assertions' => ['$a===' => 'ReflectionClass'], + ]; + } +} diff --git a/tests/Traits/ValidCodeAnalysisTestTrait.php b/tests/Traits/ValidCodeAnalysisTestTrait.php index f5f710ecbaa..ea9e70a4661 100644 --- a/tests/Traits/ValidCodeAnalysisTestTrait.php +++ b/tests/Traits/ValidCodeAnalysisTestTrait.php @@ -18,7 +18,15 @@ trait ValidCodeAnalysisTestTrait { /** - * @return iterable,ignored_issues?:list,php_version?:string}> + * @return iterable< + * string, + * array{ + * code: string, + * assertions?: array, + * ignored_issues?: list, + * php_version?: string, + * } + * > */ abstract public function providerValidCodeParse(): iterable;