From 9073f118dbf9e8f0455f2d149514efaa944302d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 18 Jun 2023 21:37:52 +0200 Subject: [PATCH] [rector] add form default data rule: handle case when there are method call on builder without add --- ...FormDefaultDataOnExportFilterAggregatorRector.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/rector/src/Rector/ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector.php b/utils/rector/src/Rector/ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector.php index cc54a24f1..4718aedac 100644 --- a/utils/rector/src/Rector/ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector.php +++ b/utils/rector/src/Rector/ChillBundleAddFormDefaultDataOnExportFilterAggregatorRector.php @@ -138,7 +138,7 @@ PHP */ } ['build_form_method' => $buildFormMethod, 'empty_to_replace' => $emptyToReplace] - = $this->filterBuildFormMethod($node->stmts[$buildFormStmtIndex]); + = $this->filterBuildFormMethod($node->stmts[$buildFormStmtIndex], $node); $node->stmts = [ ...$stmtBefore, @@ -172,7 +172,7 @@ PHP */ * @param Node\Stmt\ClassMethod $buildFormMethod * @return array{"build_form_method": Node\Stmt\ClassMethod, "empty_to_replace": array} */ - private function filterBuildFormMethod(Node\Stmt\ClassMethod $buildFormMethod): array + private function filterBuildFormMethod(Node\Stmt\ClassMethod $buildFormMethod, Node\Stmt\Class_ $node): array { $builderName = $buildFormMethod->params[0]->var->name; @@ -183,7 +183,7 @@ PHP */ if ($stmt instanceof Node\Stmt\Expression // it must be a method call && $stmt->expr instanceof Node\Expr\MethodCall - && false !== ($results = $this->handleMethodCallBuilderAdd($stmt->expr, $builderName)) + && false !== ($results = $this->handleMethodCallBuilderAdd($stmt->expr, $builderName, $node)) ) { ['stmt' => $newMethodCAll, 'emptyDataToReplace' => $newEmptyDataToReplace] = $results; $newStmts[] = new Node\Stmt\Expression($newMethodCAll); @@ -198,7 +198,7 @@ PHP */ return ['build_form_method' => $buildFormMethod, "empty_to_replace" => $emptyDataToReplace]; } - private function handleMethodCallBuilderAdd(Node\Expr\MethodCall $methodCall, string $builderName): array|false + private function handleMethodCallBuilderAdd(Node\Expr\MethodCall $methodCall, string $builderName, Node\Stmt\Class_ $node): array|false { $emptyDataToReplace = []; // check for chained method call @@ -208,7 +208,7 @@ PHP */ ) { // as this is chained, we make a recursion on this method - $resultFormDeepMethodCall = $this->handleMethodCallBuilderAdd($methodCall->var, $builderName); + $resultFormDeepMethodCall = $this->handleMethodCallBuilderAdd($methodCall->var, $builderName, $node); if (false === $resultFormDeepMethodCall) { return false; @@ -268,6 +268,6 @@ PHP */ return ['stmt' => $methodCall, 'emptyDataToReplace' => $emptyDataToReplace]; } - throw new \RuntimeException("Not supported situation"); + return ['stmt' => $methodCall, 'emptyDataToReplace' => $emptyDataToReplace]; } }