diff --git a/src/Reflection/Php/ClosureInvokeMethodReflection.php b/src/Reflection/Php/ClosureInvokeMethodReflection.php new file mode 100644 index 00000000000..1cb554b32be --- /dev/null +++ b/src/Reflection/Php/ClosureInvokeMethodReflection.php @@ -0,0 +1,106 @@ +nativeMethodReflection = $nativeMethodReflection; + $this->closureType = $closureType; + } + + public function getDeclaringClass(): ClassReflection + { + return $this->nativeMethodReflection->getDeclaringClass(); + } + + public function isStatic(): bool + { + return $this->nativeMethodReflection->isStatic(); + } + + public function isPrivate(): bool + { + return $this->nativeMethodReflection->isPrivate(); + } + + public function isPublic(): bool + { + return $this->nativeMethodReflection->isPublic(); + } + + public function getDocComment(): ?string + { + return $this->nativeMethodReflection->getDocComment(); + } + + public function getName(): string + { + return $this->nativeMethodReflection->getName(); + } + + public function getPrototype(): ClassMemberReflection + { + return $this->nativeMethodReflection->getPrototype(); + } + + public function getVariants(): array + { + return [ + new FunctionVariant( + $this->closureType->getTemplateTypeMap(), + $this->closureType->getResolvedTemplateTypeMap(), + $this->closureType->getParameters(), + $this->closureType->isVariadic(), + $this->closureType->getReturnType() + ), + ]; + } + + public function isDeprecated(): TrinaryLogic + { + return $this->nativeMethodReflection->isDeprecated(); + } + + public function getDeprecatedDescription(): ?string + { + return $this->nativeMethodReflection->getDeprecatedDescription(); + } + + public function isFinal(): TrinaryLogic + { + return $this->nativeMethodReflection->isFinal(); + } + + public function isInternal(): TrinaryLogic + { + return $this->nativeMethodReflection->isInternal(); + } + + public function getThrowType(): ?Type + { + return $this->nativeMethodReflection->getThrowType(); + } + + public function hasSideEffects(): TrinaryLogic + { + return $this->nativeMethodReflection->hasSideEffects(); + } + +} diff --git a/src/Type/ClosureType.php b/src/Type/ClosureType.php index e7d1235633a..d6fe9e10e5f 100644 --- a/src/Type/ClosureType.php +++ b/src/Type/ClosureType.php @@ -10,6 +10,7 @@ use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Reflection\Php\ClosureCallMethodReflection; +use PHPStan\Reflection\Php\ClosureInvokeMethodReflection; use PHPStan\Reflection\PropertyReflection; use PHPStan\TrinaryLogic; use PHPStan\Type\Constant\ConstantArrayType; @@ -167,6 +168,13 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ); } + if ($methodName === '__invoke') { + return new ClosureInvokeMethodReflection( + $this->objectType->getMethod($methodName, $scope), + $this + ); + } + return $this->objectType->getMethod($methodName, $scope); }