mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
[Symfony] Fix ConsoleExecuteReturnInt for nested functions
This commit is contained in:
parent
c273bf777d
commit
2bfb9e1536
@ -8,11 +8,13 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BinaryOp\Coalesce;
|
||||
use PhpParser\Node\Expr\Cast\Int_;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Rector\AbstractRector;
|
||||
@ -104,9 +106,13 @@ PHP
|
||||
$this->traverseNodesWithCallable((array) $classMethod->getStmts(), function (Node $node) use (
|
||||
$classMethod,
|
||||
&$hasReturn
|
||||
): void {
|
||||
): ?int {
|
||||
if ($node instanceof FunctionLike) {
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
}
|
||||
|
||||
if (! $node instanceof Return_) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// is there return without nesting?
|
||||
@ -115,6 +121,8 @@ PHP
|
||||
}
|
||||
|
||||
$this->setReturnTo0InsteadOfNull($node);
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if ($hasReturn) {
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Symfony\Tests\Rector\Console\ConsoleExecuteReturnIntRector\Fixture;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
final class SkipNestedReturn extends Command
|
||||
{
|
||||
public function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
array_filter([0, 1], function ($a, $b) {
|
||||
return false;
|
||||
});
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user