Skip to content

Commit

Permalink
[TypeDeclaration] Handle in inner function on ReturnTypeFromStrictTer…
Browse files Browse the repository at this point in the history
…naryRector (#5785)
  • Loading branch information
samsonasik authored Mar 31, 2024
1 parent 4c40eb6 commit d869306
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture;

final class InInnerFunction
{
public function getValue($number)
{
function foo($number)
{
return $number ? 100 : 500;
}

echo foo($number);
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\Fixture;

final class InInnerFunction
{
public function getValue($number)
{
function foo($number): int
{
return $number ? 100 : 500;
}

echo foo($number);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

$returns = $this->betterNodeFinder->findInstanceOf($node->stmts, Return_::class);
$returns = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($node, Return_::class);
if (count($returns) !== 1) {
return null;
}
Expand Down

0 comments on commit d869306

Please sign in to comment.