use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Exit_;
-use PhpParser\Node\Expr\New_;
-use PhpParser\Node\Name\FullyQualified as FullyQualifiedName;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Expression;
{
// If nodes is empty, it can't have a return value.
if (empty($nodes)) {
- return [new Return_(new New_(new FullyQualifiedName('Psy\CodeCleaner\NoReturnValue')))];
+ return [new Return_(NoReturnValue::create())];
}
- $last = end($nodes);
+ $last = \end($nodes);
// Special case a few types of statements to add an implicit return
// value (even though they technically don't have any return value)
} elseif ($last instanceof Switch_) {
foreach ($last->cases as $case) {
// only add an implicit return to cases which end in break
- $caseLast = end($case->stmts);
+ $caseLast = \end($case->stmts);
if ($caseLast instanceof Break_) {
- $case->stmts = $this->addImplicitReturn(array_slice($case->stmts, 0, -1));
+ $case->stmts = $this->addImplicitReturn(\array_slice($case->stmts, 0, -1));
$case->stmts[] = $caseLast;
}
}
} elseif ($last instanceof Expr && !($last instanceof Exit_)) {
// @codeCoverageIgnoreStart
- $nodes[count($nodes) - 1] = new Return_($last, [
+ $nodes[\count($nodes) - 1] = new Return_($last, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
]);
// @codeCoverageIgnoreEnd
} elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
// For PHP Parser 4.x
- $nodes[count($nodes) - 1] = new Return_($last->expr, [
+ $nodes[\count($nodes) - 1] = new Return_($last->expr, [
'startLine' => $last->getLine(),
'endLine' => $last->getLine(),
]);
// because code outside namespace statements doesn't really work, and
// there's already an implicit return in the namespace statement anyway.
if (self::isNonExpressionStmt($last)) {
- $nodes[] = new Return_(new New_(new FullyQualifiedName('Psy\CodeCleaner\NoReturnValue')));
+ $nodes[] = new Return_(NoReturnValue::create());
}
return $nodes;