Skip to content

Commit

Permalink
fix(phpstan): use original expression string in assert_return() dyn…
Browse files Browse the repository at this point in the history
…amic return type extension (#50)
  • Loading branch information
simPod committed May 22, 2024
1 parent 49f6ba7 commit 921721e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion phpstan/AssertReturnDynamicFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand All @@ -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
Expand Down

0 comments on commit 921721e

Please sign in to comment.