Generate no return when empty return statement

This commit is contained in:
Witold Wasiczko 2020-01-05 19:33:35 +01:00
parent e15e6b0351
commit f610206257
No known key found for this signature in database
GPG Key ID: 018185A24DB71DCD

View File

@ -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[]