From d3ff2a9c0f3c336f352061524253c79ccc5ae30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Fri, 21 Aug 2020 09:36:29 +0000 Subject: [PATCH] Fix reading of constant names --- phpstan.neon | 7 ------- src/GetPostDynamicFunctionReturnTypeExtension.php | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 31759891..8809a2e4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,10 +6,3 @@ parameters: paths: - bootstrap.php - src/ - ignoreErrors: - - - path: src/GetPostDynamicFunctionReturnTypeExtension.php - message: "#^Strict comparison using === between 'OBJECT'\\|PhpParser\\\\Node\\\\Expr and '(ARRAY_N|ARRAY_A|OBJECT)' will always evaluate to false\\.$#" - - - path: src/GetPostDynamicFunctionReturnTypeExtension.php - message: "#^Strict comparison using !== between PhpParser\\\\Node\\\\Expr and 'OBJECT' will always evaluate to true\\.$#" diff --git a/src/GetPostDynamicFunctionReturnTypeExtension.php b/src/GetPostDynamicFunctionReturnTypeExtension.php index 4098d550..e533a299 100644 --- a/src/GetPostDynamicFunctionReturnTypeExtension.php +++ b/src/GetPostDynamicFunctionReturnTypeExtension.php @@ -8,6 +8,7 @@ namespace PHPStan\WordPress; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\FunctionReflection; @@ -31,9 +32,8 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { $output = 'OBJECT'; - $argsCount = count($functionCall->args); - if ($argsCount >= 2 && $functionCall->args[1]->value !== 'OBJECT') { - $output = $functionCall->args[1]->value; + if (count($functionCall->args) >= 2 && $functionCall->args[1]->value instanceof ConstFetch) { + $output = $functionCall->args[1]->value->name->getLast(); } if ($output === 'ARRAY_A') { return TypeCombinator::union(new ArrayType(new StringType(), new MixedType()), new NullType());