From 7ca96ef1d7d596b898ff3cecdf4ad6678858c874 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 24 Apr 2022 22:08:02 +0200 Subject: [PATCH] remove current statement --- ...RefactorInternalPropertiesOfTSFERector.php | 15 +++++------- .../v10/v1/SendNotifyEmailToMailApiRector.php | 24 +++++++++---------- .../v7/BackendUtilityGetRecordRawRector.php | 12 ++++++---- .../v2/PageNotFoundAndErrorHandlingRector.php | 9 +++---- ...aInsteadReflectionServiceMethodsRector.php | 8 ++----- 5 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/Rector/v10/v1/RefactorInternalPropertiesOfTSFERector.php b/src/Rector/v10/v1/RefactorInternalPropertiesOfTSFERector.php index 2b0c098b5..32b53c9c8 100644 --- a/src/Rector/v10/v1/RefactorInternalPropertiesOfTSFERector.php +++ b/src/Rector/v10/v1/RefactorInternalPropertiesOfTSFERector.php @@ -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); } diff --git a/src/Rector/v10/v1/SendNotifyEmailToMailApiRector.php b/src/Rector/v10/v1/SendNotifyEmailToMailApiRector.php index 67dd49c42..0a9855d97 100644 --- a/src/Rector/v10/v1/SendNotifyEmailToMailApiRector.php +++ b/src/Rector/v10/v1/SendNotifyEmailToMailApiRector.php @@ -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; @@ -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(); @@ -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); } diff --git a/src/Rector/v8/v7/BackendUtilityGetRecordRawRector.php b/src/Rector/v8/v7/BackendUtilityGetRecordRawRector.php index eb8be38ff..23dcd47a4 100644 --- a/src/Rector/v8/v7/BackendUtilityGetRecordRawRector.php +++ b/src/Rector/v8/v7/BackendUtilityGetRecordRawRector.php @@ -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); } diff --git a/src/Rector/v9/v2/PageNotFoundAndErrorHandlingRector.php b/src/Rector/v9/v2/PageNotFoundAndErrorHandlingRector.php index b82b56717..7cf0d54cf 100644 --- a/src/Rector/v9/v2/PageNotFoundAndErrorHandlingRector.php +++ b/src/Rector/v9/v2/PageNotFoundAndErrorHandlingRector.php @@ -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); } @@ -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; diff --git a/src/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector.php b/src/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector.php index c3aedacba..7b58f8e24 100644 --- a/src/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector.php +++ b/src/Rector/v9/v4/UseClassSchemaInsteadReflectionServiceMethodsRector.php @@ -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; } @@ -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),