diff --git a/src/HookCallbackRule.php b/src/HookCallbackRule.php index 39bf49e..9bdfdd2 100644 --- a/src/HookCallbackRule.php +++ b/src/HookCallbackRule.php @@ -19,6 +19,7 @@ use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\VerbosityLevel; use PHPStan\Type\VoidType; +use PHPStan\Type\MixedType; /** * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\FuncCall> @@ -206,8 +207,9 @@ protected function validateFilterReturnType(ParametersAcceptor $callbackAcceptor { $returnType = $callbackAcceptor->getReturnType(); $isVoidSuperType = $returnType->isSuperTypeOf(new VoidType()); + $isMixedType = $returnType->equals(new MixedType()); - if (! $isVoidSuperType->yes()) { + if ($isMixedType || $isVoidSuperType->no()) { return; } diff --git a/tests/data/hook-callback.php b/tests/data/hook-callback.php index bf57d22..0b3fe66 100644 --- a/tests/data/hook-callback.php +++ b/tests/data/hook-callback.php @@ -185,6 +185,7 @@ add_filter('filter', function($one = null, $two = null, $three = null) { return 123; }); +add_filter('filter', 'return_mixed'); // Action callbacks must return void add_action('action', function() { @@ -248,6 +249,10 @@ function filter_variadic_typed( $one, ...$two ) : int { return 123; } +function return_mixed($value) : mixed { + return $value; +} + class TestInvokableTyped { public function __invoke($one, $two) : int { return 123;