diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/get_and_set.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/get_and_set.php.inc index d93ec6f791c..134da3a0697 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/get_and_set.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/get_and_set.php.inc @@ -21,7 +21,7 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodT final class GetAndSet { - public function __get(string $method) + public function __get(string $method): mixed { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php index 7be3745cecc..8bb419c6902 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php @@ -110,6 +110,11 @@ public function refactor(Node $node): ?Node } } + if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE) && ! $classMethod->returnType instanceof Node) { + $classMethod->returnType = new Identifier('mixed'); + $hasChanged = true; + } + if ($this->isName($classMethod, MethodName::__SET) && $this->phpVersionProvider->isAtLeastPhpVersion( PhpVersionFeature::MIXED_TYPE )) {