Skip to content

Commit

Permalink
Fix reading of constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Aug 21, 2020
1 parent cd99188 commit d3ff2a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 0 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\.$#"
6 changes: 3 additions & 3 deletions src/GetPostDynamicFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit d3ff2a9

Please sign in to comment.