mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 14:03:41 +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
|
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();
|
$anonymousFunction = new Closure();
|
||||||
$newParams = $this->copyParams($classMethod->params);
|
$newParams = $this->copyParams($classMethod->params);
|
||||||
@ -205,7 +205,7 @@ PHP
|
|||||||
}
|
}
|
||||||
|
|
||||||
// does method return something?
|
// does method return something?
|
||||||
if ($hasClassMethodReturn !== []) {
|
if ($this->hasClassMethodReturn($classMethodReturns)) {
|
||||||
$anonymousFunction->stmts[] = new Return_($innerMethodCall);
|
$anonymousFunction->stmts[] = new Return_($innerMethodCall);
|
||||||
} else {
|
} else {
|
||||||
$anonymousFunction->stmts[] = new Expression($innerMethodCall);
|
$anonymousFunction->stmts[] = new Expression($innerMethodCall);
|
||||||
@ -220,6 +220,19 @@ PHP
|
|||||||
return $anonymousFunction;
|
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
|
* @param Param[] $params
|
||||||
* @return Arg[]
|
* @return Arg[]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user