Skip to content

Commit

Permalink
add assign to variable fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jul 9, 2022
1 parent fba410b commit 08ae610
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

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

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Source\SomeResponse;

final class AssignedToVariable
{
public function action()
{
$response = new SomeResponse();

return $response;
}
}

?>
-----
<?php

declare(strict_types=1);

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

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Source\SomeResponse;

final class AssignedToVariable
{
public function action(): \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Source\SomeResponse
{
$response = new SomeResponse();

return $response;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public function refactor(Node $node): ?Node
}

$returnType = $this->typeFactory->createMixedPassedOrUnionType($newTypes);
$node->returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);

$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN);
if (! $returnTypeNode instanceof \PhpParser\Node) {
return null;
}

$node->returnType = $returnTypeNode;

return $node;
}
Expand Down

0 comments on commit 08ae610

Please sign in to comment.