Skip to content

Commit 506c87d

Browse files
committed
add known return mixed on get
1 parent d52149d commit 506c87d

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

rules-tests/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector/Fixture/get_and_set.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\KnownMagicClassMethodT
2121

2222
final class GetAndSet
2323
{
24-
public function __get(string $method)
24+
public function __get(string $method): mixed
2525
{
2626
}
2727

rules/TypeDeclaration/Rector/ClassMethod/KnownMagicClassMethodTypeRector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ public function refactor(Node $node): ?Node
110110
}
111111
}
112112

113+
if ($this->isName($classMethod, MethodName::__GET) && $this->phpVersionProvider->isAtLeastPhpVersion(
114+
PhpVersionFeature::MIXED_TYPE
115+
)) {
116+
if (! $classMethod->returnType instanceof \PhpParser\Node) {
117+
$classMethod->returnType = new Identifier('mixed');
118+
$hasChanged = true;
119+
}
120+
}
121+
113122
if ($this->isName($classMethod, MethodName::__SET) && $this->phpVersionProvider->isAtLeastPhpVersion(
114123
PhpVersionFeature::MIXED_TYPE
115124
)) {

0 commit comments

Comments
 (0)