mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Generate no return when empty return statement
This commit is contained in:
parent
e15e6b0351
commit
f610206257
@ -188,7 +188,7 @@ PHP
|
||||
*/
|
||||
private function createAnonymousFunction(ClassMethod $classMethod, Node $node): Closure
|
||||
{
|
||||
$hasClassMethodReturn = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Return_::class);
|
||||
$classMethodReturns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Return_::class);
|
||||
|
||||
$anonymousFunction = new Closure();
|
||||
$newParams = $this->copyParams($classMethod->params);
|
||||
@ -205,7 +205,7 @@ PHP
|
||||
}
|
||||
|
||||
// does method return something?
|
||||
if ($hasClassMethodReturn !== []) {
|
||||
if ($this->hasClassMethodReturn($classMethodReturns)) {
|
||||
$anonymousFunction->stmts[] = new Return_($innerMethodCall);
|
||||
} else {
|
||||
$anonymousFunction->stmts[] = new Expression($innerMethodCall);
|
||||
@ -220,6 +220,19 @@ PHP
|
||||
return $anonymousFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Return_[] $nodes
|
||||
*/
|
||||
private function hasClassMethodReturn(array $nodes): bool
|
||||
{
|
||||
foreach($nodes as $node) {
|
||||
if ($node->expr !== null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Param[] $params
|
||||
* @return Arg[]
|
||||
|
Loading…
x
Reference in New Issue
Block a user