Skip to content

Commit

Permalink
[TypeDeclaration] Allow return static from under function on ReturnTy…
Browse files Browse the repository at this point in the history
…peFromStrictTypedCallRector (#5358)
  • Loading branch information
samsonasik committed Dec 13, 2023
1 parent 0817980 commit 5a1512b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\SomeNamedConstructorClass;

function getData()
{
return SomeNamedConstructorClass::from();
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\SomeNamedConstructorClass;

function getData(): \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\SomeNamedConstructorClass
{
return SomeNamedConstructorClass::from();
}

?>
Expand Up @@ -117,11 +117,10 @@ public function resolveMethodCallReturnNode(MethodCall | StaticCall | FuncCall $
private function normalizeStaticType(MethodCall | StaticCall | FuncCall $call, Type $type): Type
{
$reflectionClass = $this->reflectionResolver->resolveClassReflection($call);
if (! $reflectionClass instanceof ClassReflection) {
return $type;
}
$currentClassName = $reflectionClass instanceof ClassReflection
? $reflectionClass->getName()
: null;

$currentClassName = $reflectionClass->getName();
return TypeTraverser::map($type, static function (Type $currentType, callable $traverseCallback) use (
$currentClassName
): Type {
Expand Down

0 comments on commit 5a1512b

Please sign in to comment.