Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rules/solid/src/Rector/If_/RemoveAlwaysElseRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ public function refactor(Node $node): ?Node
if ($this->lastStatementBreaksFlow($node)) {
return null;
}

if ($node->elseifs !== []) {
$newNode = new If_($node->cond);
$newNode->stmts = $node->stmts;

$this->addNodeBeforeNode($newNode, $node);

/** @var ElseIf_ $firstElseIf */
$firstElseIf = array_shift($node->elseifs);
$node->cond = $firstElseIf->cond;
$node->stmts = $firstElseIf->stmts;

return $node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class FunctionForeachContinue
if ($flag && empty($key)) {
continue;
}

if (empty($val)) {
$val = $key;
}
Expand Down
6 changes: 2 additions & 4 deletions src/PhpParser/Node/Commander/NodeAddingCommander.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Contract\PhpParser\Node\CommanderInterface;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeTypeResolver\Node\AttributeKey;

/**
* This class collects all to-be-added expresssions (= 1 line in code)
Expand Down Expand Up @@ -94,9 +94,7 @@ private function resolveNearestExpressionPosition(Node $node): string
}

// special case for "If_"
$parentNode = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);

if ($parentNode === null) {
if ($node instanceof If_) {
return spl_object_hash($node);
}

Expand Down