mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-29 07:20:52 +00:00
[PostRector] Using NodesToAddCollector in Rector rules (#812)
* [PostRector] Using NodesToAddCollector in Rector rules * addNodes* as well * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
c732f61317
commit
49033cecc9
|
@ -75,7 +75,7 @@ CODE_SAMPLE
|
|||
$rightArray = $node->expr;
|
||||
|
||||
$standaloneAssigns = $this->createStandaloneAssigns($leftArray, $rightArray);
|
||||
$this->addNodesAfterNode($standaloneAssigns, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($standaloneAssigns, $node);
|
||||
|
||||
$this->removeNode($node);
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$countAssign = new Assign(new Variable($variableName), $countInCond);
|
||||
$this->addNodeBeforeNode($countAssign, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($countAssign, $node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ CODE_SAMPLE
|
|||
$this->mirrorComments($assignExpression, $node);
|
||||
}
|
||||
|
||||
$this->addNodeAfterNode($assignExpression, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($assignExpression, $node);
|
||||
|
||||
++$position;
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ CODE_SAMPLE
|
|||
$preAssign = new Assign($assignVariable, $array);
|
||||
|
||||
$currentStatement = $funcCall->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
$this->addNodeBeforeNode($preAssign, $currentStatement);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($preAssign, $currentStatement);
|
||||
|
||||
return $expr;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$this->addNodeAfterNode($node->right, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($node->right, $node);
|
||||
|
||||
return $node->left;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ CODE_SAMPLE
|
|||
$jsonDataVariable = new Variable(self::JSON_DATA);
|
||||
$jsonDataAssign = new Assign($jsonDataVariable, $jsonArray);
|
||||
|
||||
$this->addNodeBeforeNode($jsonDataAssign, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($jsonDataAssign, $node);
|
||||
|
||||
return $jsonEncodeAssign;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ CODE_SAMPLE
|
|||
$jsonDataVariable = new Variable(self::JSON_DATA);
|
||||
$jsonDataAssign = new Assign($jsonDataVariable, $jsonArray);
|
||||
|
||||
$this->addNodeBeforeNode($jsonDataAssign, $assign);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($jsonDataAssign, $assign);
|
||||
|
||||
return $this->createJsonEncodeAssign($assign->var, $jsonArray);
|
||||
}
|
||||
|
|
|
@ -78,12 +78,12 @@ CODE_SAMPLE
|
|||
$newAssign = new Assign($node->var, $node->expr->expr);
|
||||
|
||||
if (! $this->isExprCallOrNew($node->expr->expr)) {
|
||||
$this->addNodeAfterNode($node->expr, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($node->expr, $node);
|
||||
return $newAssign;
|
||||
}
|
||||
|
||||
$varAssign = new Assign($node->expr->var, $node->var);
|
||||
$this->addNodeBeforeNode(new Expression($newAssign), $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Expression($newAssign), $node);
|
||||
|
||||
return $varAssign;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ CODE_SAMPLE
|
|||
|
||||
$messageVariable = new Variable('message');
|
||||
$assign = new Assign($messageVariable, $argValue);
|
||||
$this->addNodeBeforeNode($assign, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
|
||||
|
||||
$node->args[0]->value = $messageVariable;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$arrayDimFetch->dim = $node->var;
|
||||
$this->addNodeAfterNode($this->processPrePost($node), $arrayDimFetch);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($this->processPrePost($node), $arrayDimFetch);
|
||||
|
||||
return $arrayDimFetch->dim;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->stmtsHashed[$hash] = true;
|
||||
$this->addNodeAfterNode(new Nop(), $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode(new Nop(), $node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
if ($this->phpVersionConstraint >= $value->value) {
|
||||
$this->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->removeNode($if);
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
if ($this->phpVersionConstraint >= $value->value) {
|
||||
$this->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->removeNode($if);
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
if ($this->phpVersionConstraint >= $value->value) {
|
||||
$this->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->removeNode($if);
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
if ($if->cond === $instanceof) {
|
||||
$this->addNodesBeforeNode($if->stmts, $if);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
|
||||
}
|
||||
|
||||
$this->removeNode($if);
|
||||
|
|
|
@ -70,7 +70,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
foreach ($node->stmts as $stmt) {
|
||||
$this->addNodeBeforeNode($stmt, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($stmt, $node);
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
|
|
@ -106,7 +106,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->removeCurrentNode($node);
|
||||
$this->addNodesAfterNode($nodesToAdd, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$this->addNodesBeforeNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
|
||||
return $assignAndRootExprAndNodesToAdd->getRootCallerExpr();
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ CODE_SAMPLE
|
|||
$newVariable = $this->variableFromNewFactory->create($new);
|
||||
$nodesToAdd[] = $this->fluentMethodCallAsArgFactory->createFluentAsArg($methodCall, $newVariable);
|
||||
|
||||
$this->addNodesBeforeNode($nodesToAdd, $methodCall);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($nodesToAdd, $methodCall);
|
||||
$this->removeParentParent($methodCall);
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$newStmts = $this->nonFluentChainMethodCallFactory->createFromNewAndRootMethodCall($new, $node);
|
||||
$this->addNodesBeforeNode($newStmts, $node);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($newStmts, $node);
|
||||
|
||||
// change new arg to root variable
|
||||
$newVariable = $this->variableFromNewFactory->create($new);
|
||||
|
|
|
@ -113,7 +113,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->fluentNodeRemover->removeCurrentNode($node);
|
||||
$this->addNodesAfterNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->fluentNodeRemover->removeCurrentNode($node);
|
||||
$this->addNodesAfterNode($nodesToAdd, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$this->fluentNodeRemover->removeCurrentNode($node);
|
||||
$this->addNodesAfterNode($nodesToAdd, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ CODE_SAMPLE
|
|||
$funcName = new Name('ini_set');
|
||||
$iniSet = new FuncCall($funcName, [new Arg($sessionKey), new Arg($option->value)]);
|
||||
|
||||
$this->addNodeBeforeNode(new Expression($iniSet), $currentStatement);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Expression($iniSet), $currentStatement);
|
||||
}
|
||||
|
||||
unset($node->args[0]);
|
||||
|
|
|
@ -99,7 +99,7 @@ CODE_SAMPLE
|
|||
$variableAssignName = $this->variableNaming->createCountedValueName('battleShipcompare', $scope);
|
||||
$variableAssign = new Variable($variableAssignName);
|
||||
$assignExpression = $this->getAssignExpression($anonymousFunction, $variableAssign);
|
||||
$this->addNodeBeforeNode($assignExpression, $currentStatement);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($assignExpression, $currentStatement);
|
||||
|
||||
return new FuncCall($variableAssign, [new Arg($node->left), new Arg($node->right)]);
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
|
||||
if ($parent instanceof Assign) {
|
||||
$this->mirrorComments($assignExpressions[0], $parentExpression);
|
||||
$this->addNodesBeforeNode($assignExpressions, $node);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($assignExpressions, $node);
|
||||
$this->removeNode($parentExpression);
|
||||
|
||||
return $node;
|
||||
|
@ -117,7 +117,7 @@ CODE_SAMPLE
|
|||
if ($stmts === []) {
|
||||
$parent->stmts = $assignExpressions;
|
||||
} else {
|
||||
$this->addNodesBeforeNode($assignExpressions, $parent->stmts[0]);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($assignExpressions, $parent->stmts[0]);
|
||||
}
|
||||
|
||||
return $parent->valueVar;
|
||||
|
|
|
@ -70,7 +70,7 @@ CODE_SAMPLE
|
|||
continue;
|
||||
}
|
||||
|
||||
$this->addNodeAfterNode(new Catch_([$catchType], $catch->var, $catch->stmts), $node->catches[$key]);
|
||||
$this->nodesToAddCollector->addNodeAfterNode(new Catch_([$catchType], $catch->var, $catch->stmts), $node->catches[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ CODE_SAMPLE
|
|||
{
|
||||
$parent = $funcCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parent instanceof Expression) {
|
||||
$this->addNodeAfterNode($replaceEmptystringToNull, $funcCall);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $funcCall);
|
||||
return $funcCall;
|
||||
}
|
||||
|
||||
|
@ -316,12 +316,12 @@ CODE_SAMPLE
|
|||
? $cond->right
|
||||
: $cond->left;
|
||||
if ($this->valueResolver->isFalse($valueCompare)) {
|
||||
$this->addNodeAfterNode($replaceEmptystringToNull, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $if);
|
||||
}
|
||||
}
|
||||
|
||||
if ($cond instanceof BooleanNot) {
|
||||
$this->addNodeAfterNode($replaceEmptystringToNull, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $if);
|
||||
}
|
||||
|
||||
return $funcCall;
|
||||
|
@ -331,7 +331,7 @@ CODE_SAMPLE
|
|||
{
|
||||
if ($if->stmts !== []) {
|
||||
$firstStmt = $if->stmts[0];
|
||||
$this->addNodeBeforeNode($funcCall, $firstStmt);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($funcCall, $firstStmt);
|
||||
} else {
|
||||
$if->stmts[0] = new Expression($funcCall);
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ CODE_SAMPLE
|
|||
$function = $this->createClosure();
|
||||
$assign = new Assign(new Variable('streamIsatty'), $function);
|
||||
|
||||
$this->addNodeBeforeNode($assign, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
|
||||
|
||||
return new FuncCall(new Variable('streamIsatty'), $node->args);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ CODE_SAMPLE
|
|||
$array = $funcCall->args[0]->value;
|
||||
|
||||
$resetFuncCall = $this->nodeFactory->createFuncCall('reset', [$array]);
|
||||
$this->addNodeBeforeNode($resetFuncCall, $funcCall);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($resetFuncCall, $funcCall);
|
||||
|
||||
$funcCall->name = new Name('key');
|
||||
|
||||
|
@ -87,7 +87,7 @@ CODE_SAMPLE
|
|||
{
|
||||
$array = $funcCall->args[0]->value;
|
||||
$resetFuncCall = $this->nodeFactory->createFuncCall('end', [$array]);
|
||||
$this->addNodeBeforeNode($resetFuncCall, $funcCall);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($resetFuncCall, $funcCall);
|
||||
|
||||
$funcCall->name = new Name('key');
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ CODE_SAMPLE
|
|||
|
||||
// Add new nodes to do the assignment by reference
|
||||
$newNodes = $this->createAssignRefArrayFromListReferences($node->items, $exprVariable, []);
|
||||
$this->addNodesAfterNode($newNodes, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($newNodes, $node);
|
||||
|
||||
// Remove the stale params right-most-side
|
||||
return $this->removeStaleParams($node, $rightSideRemovableParamsCount);
|
||||
|
|
|
@ -210,7 +210,7 @@ CODE_SAMPLE
|
|||
);
|
||||
// Assign the value to the variable, and replace the element with the variable
|
||||
$newVariable = new Variable($variableName);
|
||||
$this->addNodeBeforeNode(new Assign($newVariable, $arrayItem->value), $array);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Assign($newVariable, $arrayItem->value), $array);
|
||||
return $newVariable;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ CODE_SAMPLE
|
|||
);
|
||||
// Assign the value to the variable
|
||||
$newVariable = new Variable($variableName);
|
||||
$this->addNodeBeforeNode(new Assign($newVariable, $allowableTagsParam), $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Assign($newVariable, $allowableTagsParam), $node);
|
||||
|
||||
// Apply refactor on the variable
|
||||
$newExpr = $this->createIsArrayTernaryFromExpression($newVariable);
|
||||
|
|
|
@ -139,7 +139,7 @@ CODE_SAMPLE
|
|||
? $ternary->cond
|
||||
: $ternary->if;
|
||||
|
||||
$this->addNodeAfterNode(new Expression($assign), $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode(new Expression($assign), $if);
|
||||
return $if;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$assign->expr = $coalesce->left;
|
||||
$this->addNodeAfterNode(new Expression($assign), $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode(new Expression($assign), $if);
|
||||
return $if;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ CODE_SAMPLE
|
|||
Foreach_ $foreach
|
||||
): Foreach_ {
|
||||
$this->removeNode($expression);
|
||||
$this->addNodeBeforeNode(new Return_($assign->expr), $breaks[0]);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Return_($assign->expr), $breaks[0]);
|
||||
$this->removeNode($breaks[0]);
|
||||
|
||||
$return->expr = $assignPreviousVariable->expr;
|
||||
|
|
|
@ -104,7 +104,7 @@ CODE_SAMPLE
|
|||
$booleanAndConditions = $this->booleanAndAnalyzer->findBooleanAndConditions($expr);
|
||||
|
||||
if (! $ifNextReturn instanceof Return_) {
|
||||
$this->addNodeAfterNode($node->stmts[0], $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($node->stmts[0], $node);
|
||||
return $this->processReplaceIfs($node, $booleanAndConditions, new Return_());
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ CODE_SAMPLE
|
|||
|
||||
$this->removeNode($ifNextReturn);
|
||||
$ifNextReturn = $node->stmts[0];
|
||||
$this->addNodeAfterNode($ifNextReturn, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($ifNextReturn, $node);
|
||||
|
||||
$ifNextReturnClone = $ifNextReturn instanceof Return_
|
||||
? clone $ifNextReturn
|
||||
|
@ -128,7 +128,7 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
$this->addNodeAfterNode(new Return_(), $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode(new Return_(), $node);
|
||||
return $this->processReplaceIfs($node, $booleanAndConditions, $ifNextReturnClone);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ CODE_SAMPLE
|
|||
$this->mirrorComments($ifs[0], $node);
|
||||
|
||||
foreach ($ifs as $if) {
|
||||
$this->addNodeBeforeNode($if, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
|
|
@ -110,7 +110,7 @@ CODE_SAMPLE
|
|||
foreach ($nestedIfsWithOnlyReturn as $key => $nestedIfWithOnlyReturn) {
|
||||
// last item → the return node
|
||||
if ($nestedIfsWithOnlyReturnCount === $key + 1) {
|
||||
$this->addNodeAfterNode($nestedIfWithOnlyReturn, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($nestedIfWithOnlyReturn, $if);
|
||||
} else {
|
||||
$this->addStandaloneIfsWithReturn($nestedIfWithOnlyReturn, $if, $nextReturn);
|
||||
}
|
||||
|
@ -127,17 +127,17 @@ CODE_SAMPLE
|
|||
if ($invertedCondition instanceof BooleanNot && $invertedCondition->expr instanceof BooleanAnd) {
|
||||
$booleanNotPartIf = new If_(new BooleanNot($invertedCondition->expr->left));
|
||||
$booleanNotPartIf->stmts = [clone $return];
|
||||
$this->addNodeAfterNode($booleanNotPartIf, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($booleanNotPartIf, $if);
|
||||
|
||||
$booleanNotPartIf = new If_(new BooleanNot($invertedCondition->expr->right));
|
||||
$booleanNotPartIf->stmts = [clone $return];
|
||||
$this->addNodeAfterNode($booleanNotPartIf, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($booleanNotPartIf, $if);
|
||||
return;
|
||||
}
|
||||
|
||||
$nestedIfWithOnlyReturn->cond = $invertedCondition;
|
||||
$nestedIfWithOnlyReturn->stmts = [clone $return];
|
||||
|
||||
$this->addNodeAfterNode($nestedIfWithOnlyReturn, $if);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($nestedIfWithOnlyReturn, $if);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ CODE_SAMPLE
|
|||
$this->mirrorComments($if, $node);
|
||||
}
|
||||
|
||||
$this->addNodeBeforeNode($if, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
|
|
@ -99,7 +99,7 @@ CODE_SAMPLE
|
|||
$this->mirrorComments($if, $node);
|
||||
}
|
||||
|
||||
$this->addNodeBeforeNode($if, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
|
|
|
@ -87,7 +87,7 @@ CODE_SAMPLE
|
|||
$if = new If_($node->cond);
|
||||
$if->stmts = $node->stmts;
|
||||
|
||||
$this->addNodeBeforeNode($if, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
|
||||
$this->mirrorComments($if, $node);
|
||||
|
||||
/** @var ElseIf_ $firstElseIf */
|
||||
|
@ -98,19 +98,19 @@ CODE_SAMPLE
|
|||
|
||||
$statements = $this->getStatementsElseIfs($node);
|
||||
if ($statements !== []) {
|
||||
$this->addNodesAfterNode($statements, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($statements, $node);
|
||||
}
|
||||
|
||||
if ($originalNode->else instanceof Else_) {
|
||||
$node->else = null;
|
||||
$this->addNodeAfterNode($originalNode->else, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($originalNode->else, $node);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
if ($node->else !== null) {
|
||||
$this->addNodesAfterNode($node->else->stmts, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($node->else->stmts, $node);
|
||||
$node->else = null;
|
||||
return $node;
|
||||
}
|
||||
|
|
|
@ -85,14 +85,14 @@ CODE_SAMPLE
|
|||
|
||||
$this->mirrorComments($ifNegations[0], $node);
|
||||
foreach ($ifNegations as $ifNegation) {
|
||||
$this->addNodeBeforeNode($ifNegation, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($ifNegation, $node);
|
||||
}
|
||||
|
||||
/** @var BooleanAnd $booleanAnd */
|
||||
$booleanAnd = $node->expr;
|
||||
|
||||
$lastReturnExpr = $this->assignAndBinaryMap->getTruthyExpr($booleanAnd->right);
|
||||
$this->addNodeBeforeNode(new Return_($lastReturnExpr), $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Return_($lastReturnExpr), $node);
|
||||
$this->removeNode($node);
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -93,11 +93,11 @@ CODE_SAMPLE
|
|||
|
||||
$this->mirrorComments($ifs[0], $node);
|
||||
foreach ($ifs as $if) {
|
||||
$this->addNodeBeforeNode($if, $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
|
||||
}
|
||||
|
||||
$lastReturnExpr = $this->assignAndBinaryMap->getTruthyExpr($booleanOr->right);
|
||||
$this->addNodeBeforeNode(new Return_($lastReturnExpr), $node);
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Return_($lastReturnExpr), $node);
|
||||
$this->removeNode($node);
|
||||
|
||||
return $node;
|
||||
|
|
|
@ -108,7 +108,7 @@ CODE_SAMPLE
|
|||
$newFuncCall = new FuncCall(new Name('mysql_fetch_array'), [$funcCall->args[0]]);
|
||||
$newAssignNode = new Assign($assign->var, new ArrayDimFetch($newFuncCall, new LNumber(0)));
|
||||
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
return $funcCall;
|
||||
}
|
||||
|
@ -120,10 +120,10 @@ CODE_SAMPLE
|
|||
$mysqlFetchRowFuncCall = new FuncCall(new Name('mysqli_fetch_row'), [$funcCall->args[0]]);
|
||||
$fetchVariable = new Variable('fetch');
|
||||
$newAssignNode = new Assign($fetchVariable, $mysqlFetchRowFuncCall);
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
$newAssignNode = new Assign($assign->var, new ArrayDimFetch($fetchVariable, new LNumber(0)));
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
return $funcCall;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ CODE_SAMPLE
|
|||
$funcCall->name = new Name('mysqli_select_db');
|
||||
|
||||
$newAssignNode = new Assign($assign->var, new FuncCall(new Name('mysqli_query'), [$funcCall->args[1]]));
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
unset($funcCall->args[1]);
|
||||
|
||||
|
@ -162,10 +162,10 @@ CODE_SAMPLE
|
|||
$mysqlFetchArrayFuncCall = new FuncCall(new Name('mysqli_fetch_array'), [$funcCall->args[0]]);
|
||||
$fetchVariable = new Variable('fetch');
|
||||
$newAssignNode = new Assign($fetchVariable, $mysqlFetchArrayFuncCall);
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
$newAssignNode = new Assign($assign->var, new ArrayDimFetch($fetchVariable, $fetchField ?? new LNumber(0)));
|
||||
$this->addNodeAfterNode($newAssignNode, $assign);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
|
||||
|
||||
return $funcCall;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ final class NonVariableToVariableOnFunctionCallRector extends AbstractRector
|
|||
$current = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
|
||||
$currentStatement = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
|
||||
$this->addNodeBeforeNode(
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(
|
||||
$replacements->getAssign(),
|
||||
$current instanceof Return_ ? $current : $currentStatement
|
||||
);
|
||||
|
|
|
@ -81,7 +81,7 @@ CODE_SAMPLE
|
|||
// only value: list(, $value) = each($values);
|
||||
if ($listNode->items[1] && $listNode->items[0] === null) {
|
||||
$nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args);
|
||||
$this->addNodeAfterNode($nextFuncCall, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node);
|
||||
|
||||
$currentFuncCall = $this->nodeFactory->createFuncCall('current', $eachFuncCall->args);
|
||||
|
||||
|
@ -98,10 +98,10 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$assign = new Assign($secondArrayItem->value, $currentFuncCall);
|
||||
$this->addNodeAfterNode($assign, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($assign, $node);
|
||||
|
||||
$nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args);
|
||||
$this->addNodeAfterNode($nextFuncCall, $node);
|
||||
$this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node);
|
||||
|
||||
$keyFuncCall = $this->nodeFactory->createFuncCall('key', $eachFuncCall->args);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ CODE_SAMPLE
|
|||
$assignVariable = $node->var;
|
||||
|
||||
$newNodes = $this->createNewNodes($assignVariable, $eachedVariable);
|
||||
$this->addNodesAfterNode($newNodes, $node);
|
||||
$this->nodesToAddCollector->addNodesAfterNode($newNodes, $node);
|
||||
$this->removeNode($node);
|
||||
|
||||
return null;
|
||||
|
|
|
@ -258,7 +258,7 @@ final class PhpSpecPromisesToPHPUnitAssertRector extends AbstractPhpSpecToPHPUni
|
|||
$methodCall->args = [];
|
||||
$funcCall->args[] = new Arg($methodCall);
|
||||
|
||||
$this->addNodesAfterNode([$assign, $funcCall], $methodCall);
|
||||
$this->nodesToAddCollector->addNodesAfterNode([$assign, $funcCall], $methodCall);
|
||||
|
||||
$this->removeNode($methodCall);
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ CODE_SAMPLE
|
|||
$unwrappedNodes = $this->unwrapClosureFactory->createAssign($resultVariable, $arg);
|
||||
|
||||
$arg->value = $resultVariable;
|
||||
$this->addNodesBeforeNode($unwrappedNodes, $node);
|
||||
$this->nodesToAddCollector->addNodesBeforeNode($unwrappedNodes, $node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user