Skip to content

Commit

Permalink
Reflection class stub updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-worman committed Dec 18, 2022
1 parent 9f15a91 commit 5ac3ef7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 0 additions & 2 deletions stubs/Php80.phpstub
Expand Up @@ -92,7 +92,6 @@ class ReflectionClass implements Reflector {
* @template J as object
* @param self<J>|class-string<J> $class
* @psalm-assert-if-true self<T&J> $this
*
* @psalm-pure
*/
public function isSubclassOf(self|string $class): bool {}
Expand All @@ -101,7 +100,6 @@ class ReflectionClass implements Reflector {
* @template J as object
* @param self<J>|interface-string<J> $interface
* @psalm-assert-if-true self<T&J> $this
*
* @psalm-pure
*/
public function implementsInterface(self|string $interface): bool {}
Expand Down
17 changes: 9 additions & 8 deletions stubs/Reflection.phpstub
Expand Up @@ -147,15 +147,13 @@ class ReflectionClass implements Reflector {
public function getReflectionConstants(?int $filter = null): array {}

/**
* @return array<class-string, self>
*
* @return array<interface-string, self>
* @psalm-pure
*/
public function getInterfaces(): array {}

/**
* @return list<class-string>
*
* @return list<interface-string>
* @psalm-pure
*/
public function getInterfaceNames(): array {}
Expand Down Expand Up @@ -192,7 +190,12 @@ class ReflectionClass implements Reflector {
*/
public function getModifiers(): bool {}

/** @psalm-pure */
/**
* @template J as object
* @param J $object
* @psalm-assert-if-true T&J $object
* @psalm-pure
*/
public function isInstance(object $object): bool {}

/**
Expand Down Expand Up @@ -225,7 +228,6 @@ class ReflectionClass implements Reflector {
* @template J as object
* @param self<J>|class-string<J> $class
* @psalm-assert-if-true self<T&J> $this
*
* @psalm-pure
*/
public function isSubclassOf($class): bool {}
Expand All @@ -250,7 +252,6 @@ class ReflectionClass implements Reflector {
* @template J as object
* @param self<J>|interface-string<J> $interface
* @psalm-assert-if-true self<T&J> $this
*
* @psalm-pure
*/
public function implementsInterface($interface): bool {}
Expand Down Expand Up @@ -279,7 +280,7 @@ class ReflectionClass implements Reflector {
public function getShortName(): string {}

/**
* @return ?array<string>
* @return ?list<trait-string>
* @psalm-ignore-nullable-return
* @psalm-pure
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/ReflectionTest.php
Expand Up @@ -32,5 +32,16 @@ public function providerValidCodeParse(): iterable
PHP,
'assertions' => ['$a===' => 'ReflectionClass<stdClass&Iterator>'],
];
yield 'ReflectionClass::isInstance' => [
'code' => <<<'PHP'
<?php
$a = new stdClass();
$b = new ReflectionClass(Iterator::class);
if (!$b->isInstance($a)) {
throw new Exception();
}
PHP,
'assertions' => ['$a===' => 'Iterator&stdClass'],
];
}
}

0 comments on commit 5ac3ef7

Please sign in to comment.