diff --git a/phpstan/AssertReturnDynamicFunctionReturnTypeExtension.php b/phpstan/AssertReturnDynamicFunctionReturnTypeExtension.php index c15fa2d..8e8dab6 100644 --- a/phpstan/AssertReturnDynamicFunctionReturnTypeExtension.php +++ b/phpstan/AssertReturnDynamicFunctionReturnTypeExtension.php @@ -9,6 +9,7 @@ use PHPStan\Analyser\TypeSpecifier; use PHPStan\Analyser\TypeSpecifierAwareExtension; use PHPStan\Analyser\TypeSpecifierContext; +use PHPStan\Node\Printer\ExprPrinter; use PHPStan\Reflection\FunctionReflection; use PHPStan\Type\DynamicFunctionReturnTypeExtension; use PHPStan\Type\Type; @@ -21,6 +22,10 @@ final class AssertReturnDynamicFunctionReturnTypeExtension implements { private TypeSpecifier $typeSpecifier; + public function __construct(private ExprPrinter $exprPrinter) + { + } + public function isFunctionSupported(FunctionReflection $functionReflection): bool { return $functionReflection->getName() === 'Cdn77\Functions\assert_return'; @@ -42,7 +47,9 @@ public function getTypeFromFunctionCall( TypeSpecifierContext::createTruthy(), ); - return $specifiedTypes->getSureTypes()['$value'][1] ?? null; + $originalExprString = $this->exprPrinter->printExpr($functionCall->getArgs()[0]->value); + + return $specifiedTypes->getSureTypes()[$originalExprString][1] ?? null; } public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void