diff --git a/phpstan.neon b/phpstan.neon index d73aeaf8..3aeae931 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,10 +12,3 @@ parameters: - path: %rootDir%/../../../src/GetPostDynamicFunctionReturnTypeExtension.php message: "#^Strict comparison using !== between PhpParser\\\\Node\\\\Expr and 'OBJECT' will always evaluate to true\\.$#" - # Accessing value of function arguments. - - - message: "#^Cannot access offset 'fields' on PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType\\.$#" - path: src/GetPostsDynamicFunctionReturnTypeExtension.php - - - message: "#^Parameter \\#1 \\$encoded_string of function parse_str expects string, PHPStan\\\\Type\\\\Constant\\\\ConstantStringType given\\.$#" - path: src/GetPostsDynamicFunctionReturnTypeExtension.php diff --git a/src/GetPostsDynamicFunctionReturnTypeExtension.php b/src/GetPostsDynamicFunctionReturnTypeExtension.php index 74c6800f..1f01bd4b 100644 --- a/src/GetPostsDynamicFunctionReturnTypeExtension.php +++ b/src/GetPostsDynamicFunctionReturnTypeExtension.php @@ -42,11 +42,21 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, // Called with an array argument if ($argumentType instanceof ConstantArrayType) { - $fields = $argumentType['fields'] ?? 'all'; + foreach($argumentType->getKeyTypes() as $index => $key) { + if (! $key instanceof ConstantStringType || $key->getValue() !== 'fields') { + continue; + } + + $fieldsType = $argumentType->getValueTypes()[$index]; + if ($fieldsType instanceof ConstantStringType) { + $fields = $fieldsType->getValue(); + } + break; + } } // Called with a string argument if ($argumentType instanceof ConstantStringType) { - parse_str($argumentType, $variables); + parse_str($argumentType->getValue(), $variables); $fields = $variables['fields'] ?? 'all'; }