diff --git a/extension.neon b/extension.neon index 47243c2..efb9c29 100644 --- a/extension.neon +++ b/extension.neon @@ -31,6 +31,10 @@ services: class: PHPStan\WordPress\GetCommentDynamicFunctionReturnTypeExtension tags: - phpstan.broker.dynamicFunctionReturnTypeExtension + - + class: PHPStan\WordPress\ShortcodeAttsDynamicFunctionReturnTypeExtension + tags: + - phpstan.broker.dynamicFunctionReturnTypeExtension parameters: bootstrapFiles: - ../../php-stubs/wordpress-stubs/wordpress-stubs.php diff --git a/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php b/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php new file mode 100644 index 0000000..d2ad64b --- /dev/null +++ b/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php @@ -0,0 +1,36 @@ +getName() === 'shortcode_atts'; + } + + public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type + { + if ($functionCall->args === []) { + return ParametersAcceptorSelector::selectFromArgs( + $scope, + $functionCall->args, + $functionReflection->getVariants() + )->getReturnType(); + } + + return $scope->getType($functionCall->args[0]->value); + } +}