Updated Rector to commit 49033cecc9

49033cecc9 [PostRector] Using NodesToAddCollector in Rector rules (#812)
This commit is contained in:
Tomas Votruba 2021-09-02 06:46:57 +00:00
parent 2f48356b1f
commit ec2e07443a
49 changed files with 92 additions and 92 deletions

View File

@ -61,7 +61,7 @@ CODE_SAMPLE
/** @var Array_ $rightArray */
$rightArray = $node->expr;
$standaloneAssigns = $this->createStandaloneAssigns($leftArray, $rightArray);
$this->addNodesAfterNode($standaloneAssigns, $node);
$this->nodesToAddCollector->addNodesAfterNode($standaloneAssigns, $node);
$this->removeNode($node);
return $node;
}

View File

@ -86,7 +86,7 @@ CODE_SAMPLE
return null;
}
$countAssign = new \PhpParser\Node\Expr\Assign(new \PhpParser\Node\Expr\Variable($variableName), $countInCond);
$this->addNodeBeforeNode($countAssign, $node);
$this->nodesToAddCollector->addNodeBeforeNode($countAssign, $node);
return $node;
}
}

View File

@ -75,7 +75,7 @@ CODE_SAMPLE
if ($position === 1) {
$this->mirrorComments($assignExpression, $node);
}
$this->addNodeAfterNode($assignExpression, $node);
$this->nodesToAddCollector->addNodeAfterNode($assignExpression, $node);
++$position;
}
$this->removeNode($node);

View File

@ -126,7 +126,7 @@ CODE_SAMPLE
$assignVariable = $funcCall->args[0]->value;
$preAssign = new \PhpParser\Node\Expr\Assign($assignVariable, $array);
$currentStatement = $funcCall->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$this->addNodeBeforeNode($preAssign, $currentStatement);
$this->nodesToAddCollector->addNodeBeforeNode($preAssign, $currentStatement);
return $expr;
}
private function refactorAssignArray(\PhpParser\Node\Expr $expr, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr

View File

@ -64,7 +64,7 @@ CODE_SAMPLE
if (!$parentNode instanceof \PhpParser\Node\Stmt\Expression) {
return null;
}
$this->addNodeAfterNode($node->right, $node);
$this->nodesToAddCollector->addNodeAfterNode($node->right, $node);
return $node->left;
}
}

View File

@ -122,7 +122,7 @@ CODE_SAMPLE
$jsonEncodeAssign = $this->createJsonEncodeAssign($node->var, $jsonArray);
$jsonDataVariable = new \PhpParser\Node\Expr\Variable(self::JSON_DATA);
$jsonDataAssign = new \PhpParser\Node\Expr\Assign($jsonDataVariable, $jsonArray);
$this->addNodeBeforeNode($jsonDataAssign, $node);
$this->nodesToAddCollector->addNodeBeforeNode($jsonDataAssign, $node);
return $jsonEncodeAssign;
}
// B. just start of a json? join with all the strings that concat so same variable
@ -201,7 +201,7 @@ CODE_SAMPLE
$jsonArray = $this->jsonArrayFactory->createFromJsonStringAndPlaceholders($stringValue, $placeholderNodes);
$jsonDataVariable = new \PhpParser\Node\Expr\Variable(self::JSON_DATA);
$jsonDataAssign = new \PhpParser\Node\Expr\Assign($jsonDataVariable, $jsonArray);
$this->addNodeBeforeNode($jsonDataAssign, $assign);
$this->nodesToAddCollector->addNodeBeforeNode($jsonDataAssign, $assign);
return $this->createJsonEncodeAssign($assign->var, $jsonArray);
}
/**

View File

@ -64,11 +64,11 @@ CODE_SAMPLE
}
$newAssign = new \PhpParser\Node\Expr\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 \PhpParser\Node\Expr\Assign($node->expr->var, $node->var);
$this->addNodeBeforeNode(new \PhpParser\Node\Stmt\Expression($newAssign), $node);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Stmt\Expression($newAssign), $node);
return $varAssign;
}
private function isExprCallOrNew(\PhpParser\Node\Expr $expr) : bool

View File

@ -71,7 +71,7 @@ CODE_SAMPLE
}
$messageVariable = new \PhpParser\Node\Expr\Variable('message');
$assign = new \PhpParser\Node\Expr\Assign($messageVariable, $argValue);
$this->addNodeBeforeNode($assign, $node);
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
$node->args[0]->value = $messageVariable;
return $node;
}

View File

@ -103,7 +103,7 @@ CODE_SAMPLE
return null;
}
$arrayDimFetch->dim = $node->var;
$this->addNodeAfterNode($this->processPrePost($node), $arrayDimFetch);
$this->nodesToAddCollector->addNodeAfterNode($this->processPrePost($node), $arrayDimFetch);
return $arrayDimFetch->dim;
}
/**

View File

@ -113,7 +113,7 @@ CODE_SAMPLE
}
}
$this->stmtsHashed[$hash] = \true;
$this->addNodeAfterNode(new \PhpParser\Node\Stmt\Nop(), $node);
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Nop(), $node);
return $node;
}
private function shouldSkip(\PhpParser\Node $nextNode) : bool

View File

@ -162,7 +162,7 @@ CODE_SAMPLE
return null;
}
if ($this->phpVersionConstraint >= $value->value) {
$this->addNodesBeforeNode($if->stmts, $if);
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
$this->removeNode($if);
}
return $constFetch;
@ -174,7 +174,7 @@ CODE_SAMPLE
return null;
}
if ($this->phpVersionConstraint >= $value->value) {
$this->addNodesBeforeNode($if->stmts, $if);
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
$this->removeNode($if);
}
return $constFetch;
@ -207,7 +207,7 @@ CODE_SAMPLE
return null;
}
if ($this->phpVersionConstraint >= $value->value) {
$this->addNodesBeforeNode($if->stmts, $if);
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
$this->removeNode($if);
}
return $constFetch;

View File

@ -129,7 +129,7 @@ CODE_SAMPLE
return null;
}
if ($if->cond === $instanceof) {
$this->addNodesBeforeNode($if->stmts, $if);
$this->nodesToAddCollector->addNodesBeforeNode($if->stmts, $if);
}
$this->removeNode($if);
return $if;

View File

@ -60,7 +60,7 @@ CODE_SAMPLE
return null;
}
foreach ($node->stmts as $stmt) {
$this->addNodeBeforeNode($stmt, $node);
$this->nodesToAddCollector->addNodeBeforeNode($stmt, $node);
}
$this->removeNode($node);
return $node;

View File

@ -95,7 +95,7 @@ CODE_SAMPLE
}
}
$this->removeCurrentNode($node);
$this->addNodesAfterNode($nodesToAdd, $node);
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
return null;
}
private function removeCurrentNode(\PhpParser\Node\Expr\MethodCall $methodCall) : void

View File

@ -134,7 +134,7 @@ CODE_SAMPLE
if (!$assignAndRootExprAndNodesToAdd instanceof \Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd) {
return null;
}
$this->addNodesBeforeNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
$this->nodesToAddCollector->addNodesBeforeNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
return $assignAndRootExprAndNodesToAdd->getRootCallerExpr();
}
private function refactorNew(\PhpParser\Node\Expr\MethodCall $methodCall, \PhpParser\Node\Expr\New_ $new) : void
@ -145,7 +145,7 @@ CODE_SAMPLE
$nodesToAdd = $this->nonFluentChainMethodCallFactory->createFromNewAndRootMethodCall($new, $methodCall);
$newVariable = $this->variableFromNewFactory->create($new);
$nodesToAdd[] = $this->fluentMethodCallAsArgFactory->createFluentAsArg($methodCall, $newVariable);
$this->addNodesBeforeNode($nodesToAdd, $methodCall);
$this->nodesToAddCollector->addNodesBeforeNode($nodesToAdd, $methodCall);
$this->removeParentParent($methodCall);
}
private function removeParentParent(\PhpParser\Node\Expr\MethodCall $methodCall) : void

View File

@ -106,7 +106,7 @@ CODE_SAMPLE
return null;
}
$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);
$rootMethodCall->args = [new \PhpParser\Node\Arg($newVariable)];

View File

@ -105,7 +105,7 @@ CODE_SAMPLE
return null;
}
$this->fluentNodeRemover->removeCurrentNode($node);
$this->addNodesAfterNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
$this->nodesToAddCollector->addNodesAfterNode($assignAndRootExprAndNodesToAdd->getNodesToAdd(), $node);
return null;
}
private function isFoundInPrevious(\PhpParser\Node\Stmt $stmt, ?\PhpParser\Node $previous) : bool

View File

@ -101,7 +101,7 @@ CODE_SAMPLE
return null;
}
$this->fluentNodeRemover->removeCurrentNode($node);
$this->addNodesAfterNode($nodesToAdd, $node);
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
return null;
}
/**

View File

@ -88,7 +88,7 @@ CODE_SAMPLE
$nodesToAdd[\key($nodesToAdd)] = new \PhpParser\Node\Stmt\Return_($lastNodeToAdd);
}
$this->fluentNodeRemover->removeCurrentNode($node);
$this->addNodesAfterNode($nodesToAdd, $node);
$this->nodesToAddCollector->addNodesAfterNode($nodesToAdd, $node);
return $node;
}
private function matchReturnMethodCall(\PhpParser\Node\Stmt\Return_ $return) : ?\PhpParser\Node\Expr

View File

@ -64,7 +64,7 @@ CODE_SAMPLE
$sessionKey = new \PhpParser\Node\Scalar\String_('session.' . $option->key->value);
$funcName = new \PhpParser\Node\Name('ini_set');
$iniSet = new \PhpParser\Node\Expr\FuncCall($funcName, [new \PhpParser\Node\Arg($sessionKey), new \PhpParser\Node\Arg($option->value)]);
$this->addNodeBeforeNode(new \PhpParser\Node\Stmt\Expression($iniSet), $currentStatement);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Stmt\Expression($iniSet), $currentStatement);
}
unset($node->args[0]);
return $node;

View File

@ -87,7 +87,7 @@ CODE_SAMPLE
$variableAssignName = $this->variableNaming->createCountedValueName('battleShipcompare', $scope);
$variableAssign = new \PhpParser\Node\Expr\Variable($variableAssignName);
$assignExpression = $this->getAssignExpression($anonymousFunction, $variableAssign);
$this->addNodeBeforeNode($assignExpression, $currentStatement);
$this->nodesToAddCollector->addNodeBeforeNode($assignExpression, $currentStatement);
return new \PhpParser\Node\Expr\FuncCall($variableAssign, [new \PhpParser\Node\Arg($node->left), new \PhpParser\Node\Arg($node->right)]);
}
private function getAssignExpression(\PhpParser\Node\Expr\Closure $closure, \PhpParser\Node\Expr\Variable $variable) : \PhpParser\Node\Stmt\Expression

View File

@ -94,7 +94,7 @@ CODE_SAMPLE
}
if ($parent instanceof \PhpParser\Node\Expr\Assign) {
$this->mirrorComments($assignExpressions[0], $parentExpression);
$this->addNodesBeforeNode($assignExpressions, $node);
$this->nodesToAddCollector->addNodesBeforeNode($assignExpressions, $node);
$this->removeNode($parentExpression);
return $node;
}
@ -107,7 +107,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;
}

View File

@ -57,7 +57,7 @@ CODE_SAMPLE
if ($keyCatchType === 0) {
continue;
}
$this->addNodeAfterNode(new \PhpParser\Node\Stmt\Catch_([$catchType], $catch->var, $catch->stmts), $node->catches[$key]);
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Catch_([$catchType], $catch->var, $catch->stmts), $node->catches[$key]);
}
}
if ($this->nodeComparator->areNodesEqual($originalCatches, $node->catches)) {

View File

@ -213,7 +213,7 @@ CODE_SAMPLE
{
$parent = $funcCall->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if ($parent instanceof \PhpParser\Node\Stmt\Expression) {
$this->addNodeAfterNode($replaceEmptystringToNull, $funcCall);
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $funcCall);
return $funcCall;
}
if ($parent instanceof \PhpParser\Node\Stmt\If_ && $parent->cond === $funcCall) {
@ -243,11 +243,11 @@ CODE_SAMPLE
if ($cond instanceof \PhpParser\Node\Expr\BinaryOp\Identical) {
$valueCompare = $cond->left === $funcCall ? $cond->right : $cond->left;
if ($this->valueResolver->isFalse($valueCompare)) {
$this->addNodeAfterNode($replaceEmptystringToNull, $if);
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $if);
}
}
if ($cond instanceof \PhpParser\Node\Expr\BooleanNot) {
$this->addNodeAfterNode($replaceEmptystringToNull, $if);
$this->nodesToAddCollector->addNodeAfterNode($replaceEmptystringToNull, $if);
}
return $funcCall;
}
@ -255,7 +255,7 @@ CODE_SAMPLE
{
if ($if->stmts !== []) {
$firstStmt = $if->stmts[0];
$this->addNodeBeforeNode($funcCall, $firstStmt);
$this->nodesToAddCollector->addNodeBeforeNode($funcCall, $firstStmt);
} else {
$if->stmts[0] = new \PhpParser\Node\Stmt\Expression($funcCall);
}

View File

@ -96,7 +96,7 @@ CODE_SAMPLE
}
$function = $this->createClosure();
$assign = new \PhpParser\Node\Expr\Assign(new \PhpParser\Node\Expr\Variable('streamIsatty'), $function);
$this->addNodeBeforeNode($assign, $node);
$this->nodesToAddCollector->addNodeBeforeNode($assign, $node);
return new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Expr\Variable('streamIsatty'), $node->args);
}
private function createClosure() : \PhpParser\Node\Expr\Closure

View File

@ -63,7 +63,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 \PhpParser\Node\Name('key');
return $funcCall;
}
@ -71,7 +71,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 \PhpParser\Node\Name('key');
return $funcCall;
}

View File

@ -92,7 +92,7 @@ CODE_SAMPLE
$rightSideRemovableParamsCount = $this->countRightSideMostParamsByRefOrEmpty($node->items);
// 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);
}

View File

@ -182,7 +182,7 @@ CODE_SAMPLE
$variableName = $this->variableNaming->resolveFromNodeWithScopeCountAndFallbackName($array, $nodeScope, 'item' . $position . 'Unpacked');
// Assign the value to the variable, and replace the element with the variable
$newVariable = new \PhpParser\Node\Expr\Variable($variableName);
$this->addNodeBeforeNode(new \PhpParser\Node\Expr\Assign($newVariable, $arrayItem->value), $array);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Expr\Assign($newVariable, $arrayItem->value), $array);
return $newVariable;
}
/**

View File

@ -104,7 +104,7 @@ CODE_SAMPLE
$variableName = $this->variableNaming->resolveFromFuncCallFirstArgumentWithSuffix($node, 'AllowableTags', 'allowableTags', $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE));
// Assign the value to the variable
$newVariable = new \PhpParser\Node\Expr\Variable($variableName);
$this->addNodeBeforeNode(new \PhpParser\Node\Expr\Assign($newVariable, $allowableTagsParam), $node);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Expr\Assign($newVariable, $allowableTagsParam), $node);
// Apply refactor on the variable
$newExpr = $this->createIsArrayTernaryFromExpression($newVariable);
}

View File

@ -128,7 +128,7 @@ CODE_SAMPLE
return $if;
}
$assign->expr = $ternary->if === null ? $ternary->cond : $ternary->if;
$this->addNodeAfterNode(new \PhpParser\Node\Stmt\Expression($assign), $if);
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Expression($assign), $if);
return $if;
}
private function processCoalesce(\PhpParser\Node\Expr\BinaryOp\Coalesce $coalesce, ?\PhpParser\Node\Expr\Assign $assign) : ?\PhpParser\Node\Stmt\If_
@ -145,7 +145,7 @@ CODE_SAMPLE
return $if;
}
$assign->expr = $coalesce->left;
$this->addNodeAfterNode(new \PhpParser\Node\Stmt\Expression($assign), $if);
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Expression($assign), $if);
return $if;
}
private function hasThrowInAssignExpr(\PhpParser\Node\Expr\Assign $assign) : bool

View File

@ -115,7 +115,7 @@ CODE_SAMPLE
private function processEarlyReturn(\PhpParser\Node\Stmt\Expression $expression, \PhpParser\Node\Expr\Assign $assign, array $breaks, \PhpParser\Node\Stmt\Return_ $return, \PhpParser\Node\Expr\Assign $assignPreviousVariable, \PhpParser\Node\Stmt\Foreach_ $foreach) : \PhpParser\Node\Stmt\Foreach_
{
$this->removeNode($expression);
$this->addNodeBeforeNode(new \PhpParser\Node\Stmt\Return_($assign->expr), $breaks[0]);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Stmt\Return_($assign->expr), $breaks[0]);
$this->removeNode($breaks[0]);
$return->expr = $assignPreviousVariable->expr;
$this->removeNode($assignPreviousVariable);

View File

@ -111,7 +111,7 @@ CODE_SAMPLE
$expr = $node->cond;
$booleanAndConditions = $this->booleanAndAnalyzer->findBooleanAndConditions($expr);
if (!$ifNextReturn instanceof \PhpParser\Node\Stmt\Return_) {
$this->addNodeAfterNode($node->stmts[0], $node);
$this->nodesToAddCollector->addNodeAfterNode($node->stmts[0], $node);
return $this->processReplaceIfs($node, $booleanAndConditions, new \PhpParser\Node\Stmt\Return_());
}
if ($ifNextReturn instanceof \PhpParser\Node\Stmt\Return_ && $ifNextReturn->expr instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
@ -119,7 +119,7 @@ CODE_SAMPLE
}
$this->removeNode($ifNextReturn);
$ifNextReturn = $node->stmts[0];
$this->addNodeAfterNode($ifNextReturn, $node);
$this->nodesToAddCollector->addNodeAfterNode($ifNextReturn, $node);
$ifNextReturnClone = $ifNextReturn instanceof \PhpParser\Node\Stmt\Return_ ? clone $ifNextReturn : new \PhpParser\Node\Stmt\Return_();
if (!$this->contextAnalyzer->isInLoop($node)) {
return $this->processReplaceIfs($node, $booleanAndConditions, $ifNextReturnClone);
@ -127,7 +127,7 @@ CODE_SAMPLE
if (!$ifNextReturn instanceof \PhpParser\Node\Stmt\Expression) {
return null;
}
$this->addNodeAfterNode(new \PhpParser\Node\Stmt\Return_(), $node);
$this->nodesToAddCollector->addNodeAfterNode(new \PhpParser\Node\Stmt\Return_(), $node);
return $this->processReplaceIfs($node, $booleanAndConditions, $ifNextReturnClone);
}
/**
@ -139,7 +139,7 @@ CODE_SAMPLE
$ifs = $this->invertedIfFactory->createFromConditions($node, $conditions, $ifNextReturnClone);
$this->mirrorComments($ifs[0], $node);
foreach ($ifs as $if) {
$this->addNodeBeforeNode($if, $node);
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
}
$this->removeNode($node);
if (!$node->stmts[0] instanceof \PhpParser\Node\Stmt\Return_ && $ifNextReturnClone->expr instanceof \PhpParser\Node\Expr) {

View File

@ -104,7 +104,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);
}
@ -118,14 +118,14 @@ CODE_SAMPLE
if ($invertedCondition instanceof \PhpParser\Node\Expr\BooleanNot && $invertedCondition->expr instanceof \PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
$booleanNotPartIf = new \PhpParser\Node\Stmt\If_(new \PhpParser\Node\Expr\BooleanNot($invertedCondition->expr->left));
$booleanNotPartIf->stmts = [clone $return];
$this->addNodeAfterNode($booleanNotPartIf, $if);
$this->nodesToAddCollector->addNodeAfterNode($booleanNotPartIf, $if);
$booleanNotPartIf = new \PhpParser\Node\Stmt\If_(new \PhpParser\Node\Expr\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);
}
}

View File

@ -94,7 +94,7 @@ CODE_SAMPLE
if ($key === 0) {
$this->mirrorComments($if, $node);
}
$this->addNodeBeforeNode($if, $node);
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
}
$this->removeNode($node);
return $node;

View File

@ -88,7 +88,7 @@ CODE_SAMPLE
if ($key === 0) {
$this->mirrorComments($if, $node);
}
$this->addNodeBeforeNode($if, $node);
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
}
$this->removeNode($node);
return $node;

View File

@ -73,7 +73,7 @@ CODE_SAMPLE
$originalNode = clone $node;
$if = new \PhpParser\Node\Stmt\If_($node->cond);
$if->stmts = $node->stmts;
$this->addNodeBeforeNode($if, $node);
$this->nodesToAddCollector->addNodeBeforeNode($if, $node);
$this->mirrorComments($if, $node);
/** @var ElseIf_ $firstElseIf */
$firstElseIf = \array_shift($node->elseifs);
@ -82,16 +82,16 @@ CODE_SAMPLE
$this->mirrorComments($node, $firstElseIf);
$statements = $this->getStatementsElseIfs($node);
if ($statements !== []) {
$this->addNodesAfterNode($statements, $node);
$this->nodesToAddCollector->addNodesAfterNode($statements, $node);
}
if ($originalNode->else instanceof \PhpParser\Node\Stmt\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;
}

View File

@ -84,12 +84,12 @@ 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 \PhpParser\Node\Stmt\Return_($lastReturnExpr), $node);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Stmt\Return_($lastReturnExpr), $node);
$this->removeNode($node);
return $node;
}

View File

@ -90,10 +90,10 @@ 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 \PhpParser\Node\Stmt\Return_($lastReturnExpr), $node);
$this->nodesToAddCollector->addNodeBeforeNode(new \PhpParser\Node\Stmt\Return_($lastReturnExpr), $node);
$this->removeNode($node);
return $node;
}

View File

@ -81,7 +81,7 @@ CODE_SAMPLE
$funcCall->name = new \PhpParser\Node\Name(self::MYSQLI_DATA_SEEK);
$newFuncCall = new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('mysql_fetch_array'), [$funcCall->args[0]]);
$newAssignNode = new \PhpParser\Node\Expr\Assign($assign->var, new \PhpParser\Node\Expr\ArrayDimFetch($newFuncCall, new \PhpParser\Node\Scalar\LNumber(0)));
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
return $funcCall;
}
private function processMysqlDbName(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
@ -90,16 +90,16 @@ CODE_SAMPLE
$mysqlFetchRowFuncCall = new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('mysqli_fetch_row'), [$funcCall->args[0]]);
$fetchVariable = new \PhpParser\Node\Expr\Variable('fetch');
$newAssignNode = new \PhpParser\Node\Expr\Assign($fetchVariable, $mysqlFetchRowFuncCall);
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
$newAssignNode = new \PhpParser\Node\Expr\Assign($assign->var, new \PhpParser\Node\Expr\ArrayDimFetch($fetchVariable, new \PhpParser\Node\Scalar\LNumber(0)));
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
return $funcCall;
}
private function processMysqliSelectDb(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall) : \PhpParser\Node\Expr\FuncCall
{
$funcCall->name = new \PhpParser\Node\Name('mysqli_select_db');
$newAssignNode = new \PhpParser\Node\Expr\Assign($assign->var, new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('mysqli_query'), [$funcCall->args[1]]));
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
unset($funcCall->args[1]);
return $funcCall;
}
@ -119,9 +119,9 @@ CODE_SAMPLE
$mysqlFetchArrayFuncCall = new \PhpParser\Node\Expr\FuncCall(new \PhpParser\Node\Name('mysqli_fetch_array'), [$funcCall->args[0]]);
$fetchVariable = new \PhpParser\Node\Expr\Variable('fetch');
$newAssignNode = new \PhpParser\Node\Expr\Assign($fetchVariable, $mysqlFetchArrayFuncCall);
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
$newAssignNode = new \PhpParser\Node\Expr\Assign($assign->var, new \PhpParser\Node\Expr\ArrayDimFetch($fetchVariable, $fetchField ?? new \PhpParser\Node\Scalar\LNumber(0)));
$this->addNodeAfterNode($newAssignNode, $assign);
$this->nodesToAddCollector->addNodeAfterNode($newAssignNode, $assign);
return $funcCall;
}
private function processFieldToFieldDirect(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Expr\FuncCall $funcCall) : ?\PhpParser\Node\Expr\Assign

View File

@ -85,7 +85,7 @@ final class NonVariableToVariableOnFunctionCallRector extends \Rector\Core\Recto
$replacements = $this->getReplacementsFor($argument, $currentScope, $scopeNode);
$current = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$currentStatement = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$this->addNodeBeforeNode($replacements->getAssign(), $current instanceof \PhpParser\Node\Stmt\Return_ ? $current : $currentStatement);
$this->nodesToAddCollector->addNodeBeforeNode($replacements->getAssign(), $current instanceof \PhpParser\Node\Stmt\Return_ ? $current : $currentStatement);
$node->args[$key]->value = $replacements->getVariable();
// add variable name to scope, so we prevent duplication of new variable of the same name
$currentScope = $currentScope->assignExpression($replacements->getVariable(), $currentScope->getType($replacements->getVariable()));

View File

@ -69,7 +69,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);
$secondArrayItem = $listNode->items[1];
return new \PhpParser\Node\Expr\Assign($secondArrayItem->value, $currentFuncCall);
@ -81,9 +81,9 @@ CODE_SAMPLE
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
$assign = new \PhpParser\Node\Expr\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);
$firstArrayItem = $listNode->items[0];
if (!$firstArrayItem instanceof \PhpParser\Node\Expr\ArrayItem) {

View File

@ -61,7 +61,7 @@ CODE_SAMPLE
$eachedVariable = $eachFuncCall->args[0]->value;
$assignVariable = $node->var;
$newNodes = $this->createNewNodes($assignVariable, $eachedVariable);
$this->addNodesAfterNode($newNodes, $node);
$this->nodesToAddCollector->addNodesAfterNode($newNodes, $node);
$this->removeNode($node);
return null;
}

View File

@ -236,7 +236,7 @@ final class PhpSpecPromisesToPHPUnitAssertRector extends \Rector\PhpSpecToPHPUni
$methodCall->var = $this->getTestedObjectPropertyFetch();
$methodCall->args = [];
$funcCall->args[] = new \PhpParser\Node\Arg($methodCall);
$this->addNodesAfterNode([$assign, $funcCall], $methodCall);
$this->nodesToAddCollector->addNodesAfterNode([$assign, $funcCall], $methodCall);
$this->removeNode($methodCall);
return;
}

View File

@ -91,7 +91,7 @@ CODE_SAMPLE
$resultVariable = new \PhpParser\Node\Expr\Variable('result');
$unwrappedNodes = $this->unwrapClosureFactory->createAssign($resultVariable, $arg);
$arg->value = $resultVariable;
$this->addNodesBeforeNode($unwrappedNodes, $node);
$this->nodesToAddCollector->addNodesBeforeNode($unwrappedNodes, $node);
return $node;
}
return null;

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'c732f61317d64898b7b31ab171d7f1e52caca9f9';
public const PACKAGE_VERSION = '49033cecc9cd2b553f0ab3e220168c1e8da5c5b1';
/**
* @var string
*/
public const RELEASE_DATE = '2021-09-02 08:14:16';
public const RELEASE_DATE = '2021-09-02 13:31:58';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210902\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528::getLoader();
return ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528
class ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitc170ee17c921c1ac077ac893c8954528::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitc170ee17c921c1ac077ac893c8954528::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirec170ee17c921c1ac077ac893c8954528($fileIdentifier, $file);
composerRequirecec9881ea3855c0babd8d3044d8c57c5($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequirec170ee17c921c1ac077ac893c8954528($fileIdentifier, $file)
function composerRequirecec9881ea3855c0babd8d3044d8c57c5($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitc170ee17c921c1ac077ac893c8954528
class ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3856,9 +3856,9 @@ class ComposerStaticInitc170ee17c921c1ac077ac893c8954528
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc170ee17c921c1ac077ac893c8954528::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc170ee17c921c1ac077ac893c8954528::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc170ee17c921c1ac077ac893c8954528::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcec9881ea3855c0babd8d3044d8c57c5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210902\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528', false) && !interface_exists('ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528', false) && !trait_exists('ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528', false)) {
spl_autoload_call('RectorPrefix20210902\ComposerAutoloaderInitc170ee17c921c1ac077ac893c8954528');
if (!class_exists('ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5', false) && !interface_exists('ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5', false) && !trait_exists('ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5', false)) {
spl_autoload_call('RectorPrefix20210902\ComposerAutoloaderInitcec9881ea3855c0babd8d3044d8c57c5');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20210902\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3311,9 +3311,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210902\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirec170ee17c921c1ac077ac893c8954528')) {
function composerRequirec170ee17c921c1ac077ac893c8954528() {
return \RectorPrefix20210902\composerRequirec170ee17c921c1ac077ac893c8954528(...func_get_args());
if (!function_exists('composerRequirecec9881ea3855c0babd8d3044d8c57c5')) {
function composerRequirecec9881ea3855c0babd8d3044d8c57c5() {
return \RectorPrefix20210902\composerRequirecec9881ea3855c0babd8d3044d8c57c5(...func_get_args());
}
}
if (!function_exists('parseArgs')) {