Skip to content

Commit

Permalink
prevent failing when analyzing __invoke call on Closure (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Nov 25, 2024
1 parent 58ea1e7 commit 9117fe2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Infer/Reflector/MethodReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function getMethodCode(): string

public function getReflection(): ReflectionMethod
{
return new ReflectionMethod($this->className, $this->name);
/**
* \ReflectionMethod could've been used here, but for `\Closure::__invoke` it fails when constructed manually
*/
return (new \ReflectionClass($this->className))->getMethod($this->name);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Infer/ReferenceResolutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,9 @@ public function car()

expect($type->toString())->toBe('string(foo)');
});

it('handles invokable call to Closure type without failing (#636)', function () {
$type = getStatementType('(new \Closure)("foo")');

expect($type->toString())->toBe('unknown');
});

0 comments on commit 9117fe2

Please sign in to comment.