mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[rector] add form default data rule: handle case when there are method call on builder without add
This commit is contained in:
parent
21f11fb034
commit
9073f118db
@ -138,7 +138,7 @@ PHP */
|
|||||||
}
|
}
|
||||||
|
|
||||||
['build_form_method' => $buildFormMethod, 'empty_to_replace' => $emptyToReplace]
|
['build_form_method' => $buildFormMethod, 'empty_to_replace' => $emptyToReplace]
|
||||||
= $this->filterBuildFormMethod($node->stmts[$buildFormStmtIndex]);
|
= $this->filterBuildFormMethod($node->stmts[$buildFormStmtIndex], $node);
|
||||||
|
|
||||||
$node->stmts = [
|
$node->stmts = [
|
||||||
...$stmtBefore,
|
...$stmtBefore,
|
||||||
@ -172,7 +172,7 @@ PHP */
|
|||||||
* @param Node\Stmt\ClassMethod $buildFormMethod
|
* @param Node\Stmt\ClassMethod $buildFormMethod
|
||||||
* @return array{"build_form_method": Node\Stmt\ClassMethod, "empty_to_replace": array<string, mixed>}
|
* @return array{"build_form_method": Node\Stmt\ClassMethod, "empty_to_replace": array<string, mixed>}
|
||||||
*/
|
*/
|
||||||
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;
|
$builderName = $buildFormMethod->params[0]->var->name;
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ PHP */
|
|||||||
if ($stmt instanceof Node\Stmt\Expression
|
if ($stmt instanceof Node\Stmt\Expression
|
||||||
// it must be a method call
|
// it must be a method call
|
||||||
&& $stmt->expr instanceof Node\Expr\MethodCall
|
&& $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;
|
['stmt' => $newMethodCAll, 'emptyDataToReplace' => $newEmptyDataToReplace] = $results;
|
||||||
$newStmts[] = new Node\Stmt\Expression($newMethodCAll);
|
$newStmts[] = new Node\Stmt\Expression($newMethodCAll);
|
||||||
@ -198,7 +198,7 @@ PHP */
|
|||||||
return ['build_form_method' => $buildFormMethod, "empty_to_replace" => $emptyDataToReplace];
|
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 = [];
|
$emptyDataToReplace = [];
|
||||||
// check for chained method call
|
// check for chained method call
|
||||||
@ -208,7 +208,7 @@ PHP */
|
|||||||
) {
|
) {
|
||||||
// as this is chained, we make a recursion on this method
|
// 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) {
|
if (false === $resultFormDeepMethodCall) {
|
||||||
return false;
|
return false;
|
||||||
@ -268,6 +268,6 @@ PHP */
|
|||||||
return ['stmt' => $methodCall, 'emptyDataToReplace' => $emptyDataToReplace];
|
return ['stmt' => $methodCall, 'emptyDataToReplace' => $emptyDataToReplace];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException("Not supported situation");
|
return ['stmt' => $methodCall, 'emptyDataToReplace' => $emptyDataToReplace];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user