From 506c87dc9fe8637c5e77ecb9449b0fbbf962e32a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 5 Oct 2025 00:07:41 +0200 Subject: [PATCH 1/2] add known return mixed on get --- .../Fixture/get_and_set.php.inc | 2 +- .../ClassMethod/KnownMagicClassMethodTypeRector.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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..66eed24be31 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php @@ -110,6 +110,15 @@ public function refactor(Node $node): ?Node } } + if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion( + PhpVersionFeature::MIXED_TYPE + )) { + if (! $classMethod->returnType instanceof \PhpParser\Node) { + $classMethod->returnType = new Identifier('mixed'); + $hasChanged = true; + } + } + if ($this->isName($classMethod, MethodName::__SET) && $this->phpVersionProvider->isAtLeastPhpVersion( PhpVersionFeature::MIXED_TYPE )) { From 9b8a5d085330b2715d5154cf8dd2ccb23b296b74 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 4 Oct 2025 22:10:58 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- .../ClassMethod/KnownMagicClassMethodTypeRector.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php index 66eed24be31..8bb419c6902 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php @@ -110,13 +110,9 @@ public function refactor(Node $node): ?Node } } - if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion( - PhpVersionFeature::MIXED_TYPE - )) { - if (! $classMethod->returnType instanceof \PhpParser\Node) { - $classMethod->returnType = new Identifier('mixed'); - $hasChanged = true; - } + 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(