Skip to content

Commit

Permalink
remove current statement
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Apr 24, 2022
1 parent 9525bec commit 7ca96ef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
15 changes: 6 additions & 9 deletions src/Rector/v10/v1/RefactorInternalPropertiesOfTSFERector.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,14 @@ private function getRelevantParametersFromCacheHashCalculator(): Node
return $ifNode;
}

private function refactorCacheHashArray(PropertyFetch $node): Node
private function refactorCacheHashArray(PropertyFetch $propertyFetch): Node
{
$currentStmts = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
$positionNode = $currentStmts ?? $node;
$this->nodesToAddCollector->addNodeBeforeNode($this->initializeEmptyArray(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->initializePageArguments(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->initializeQueryParams(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode(
$this->nodesToAddCollector->addNodesBeforeNode([
$this->initializeEmptyArray(),
$this->initializePageArguments(),
$this->initializeQueryParams(),
$this->getRelevantParametersFromCacheHashCalculator(),
$positionNode
);
], $propertyFetch);

return new Variable(self::RELEVANT_PARAMETERS_FOR_CACHING_FROM_PAGE_ARGUMENTS);
}
Expand Down
24 changes: 11 additions & 13 deletions src/Rector/v10/v1/SendNotifyEmailToMailApiRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use PhpParser\Node\Stmt\If_;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand Down Expand Up @@ -103,20 +102,19 @@ public function refactor(Node $node): ?Node
return null;
}

$currentStmts = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
$positionNode = $currentStmts ?? $node;

$this->nodesToAddCollector->addNodeBeforeNode($this->initializeSuccessVariable(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->initializeMailClass(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->trimMessage($node), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->trimSenderName($node), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->trimSenderAddress($node), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->ifSenderAddress(), $positionNode);
$this->nodesToAddCollector->addNodesBeforeNode([
$this->initializeSuccessVariable(),
$this->initializeMailClass(),
$this->trimMessage($node),
$this->trimSenderName($node),
$this->trimSenderAddress($node),
$this->ifSenderAddress(),
], $node);

$replyTo = isset($node->args[5]) ? $node->args[5]->value : null;
if (null !== $replyTo) {
$this->nodesToAddCollector->addNodeBeforeNode($this->parsedReplyTo($replyTo), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->methodReplyTo(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->parsedReplyTo($replyTo), $node);
$this->nodesToAddCollector->addNodeBeforeNode($this->methodReplyTo(), $node);
}

$ifMessageNotEmpty = $this->messageNotEmpty();
Expand All @@ -127,7 +125,7 @@ public function refactor(Node $node): ?Node
$ifMessageNotEmpty->stmts[] = $this->ifParsedRecipients();
$ifMessageNotEmpty->stmts[] = $this->createSuccessTrue();

$this->nodesToAddCollector->addNodeBeforeNode($ifMessageNotEmpty, $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($ifMessageNotEmpty, $node);

return new Variable(self::SUCCESS);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Rector/v8/v7/BackendUtilityGetRecordRawRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ public function refactor(Node $node): ?Node
$this->nodeFactory->createMethodCall(new Variable(self::QUERY_BUILDER), 'getRestrictions'),
'removeAll'
);
$this->nodesToAddCollector->addNodeBeforeNode(new Nop(), $node);
$this->nodesToAddCollector->addNodeBeforeNode($queryBuilderAssignment, $node);
$this->nodesToAddCollector->addNodeBeforeNode($queryBuilderRemoveRestrictions, $node);
$this->nodesToAddCollector->addNodeBeforeNode(new Nop(), $node);

$this->nodesToAddCollector->addNodesBeforeNode([
new Nop(),
$queryBuilderAssignment,
$queryBuilderRemoveRestrictions,
new Nop(),
], $node);

return $this->fetchQueryBuilderResults($firstArgument, $secondArgument, $thirdArgument);
}

Expand Down
9 changes: 3 additions & 6 deletions src/Rector/v9/v2/PageNotFoundAndErrorHandlingRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@ public function refactor(Node $node): ?Node
return $this->refactorCheckPageUnavailableHandlerMethod();
}

$currentStmts = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
$positionNode = $currentStmts ?? $node;

if ($this->isNames($node->name, ['pageUnavailableHandler', 'pageNotFoundHandler', 'pageErrorHandler'])) {
$newNode = $this->refactorPageErrorHandlerIfPossible($node);
if (null !== $newNode) {
$this->nodesToAddCollector->addNodeBeforeNode($newNode, $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($newNode, $node);
$this->removeNodeOrParentNode($node);
}

Expand All @@ -139,8 +136,8 @@ public function refactor(Node $node): ?Node
return null;
}

$this->nodesToAddCollector->addNodeBeforeNode($responseNode, $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($this->throwException(), $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($responseNode, $node);
$this->nodesToAddCollector->addNodeBeforeNode($this->throwException(), $node);
$this->removeNodeOrParentNode($node);

return $node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ private function refactorGetPropertyTagsValuesMethod(MethodCall $node): ?Node
$this->nodeFactory->createArray([])
)));

$currentStmt = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
$positionNode = $currentStmt ?? $node;
$this->nodesToAddCollector->addNodeBeforeNode($propertyTagsValuesNode, $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($propertyTagsValuesNode, $node);

return $propertyTagsValuesVariable;
}
Expand Down Expand Up @@ -301,9 +299,7 @@ private function refactorIsPropertyTaggedWith(MethodCall $node): ?Node
[$node->args[1]->value]
)));

$currentStmt = $node->getAttribute(AttributeKey::CURRENT_STATEMENT);
$positionNode = $currentStmt ?? $node;
$this->nodesToAddCollector->addNodeBeforeNode($propertyNode, $positionNode);
$this->nodesToAddCollector->addNodeBeforeNode($propertyNode, $node);

return new Ternary(
new Empty_($propertyVariable),
Expand Down

0 comments on commit 7ca96ef

Please sign in to comment.