diff --git a/rules-tests/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector/Fixture/on_collection.php.inc b/rules-tests/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector/Fixture/on_collection.php.inc new file mode 100644 index 000000000..3015cb5b3 --- /dev/null +++ b/rules-tests/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector/Fixture/on_collection.php.inc @@ -0,0 +1,41 @@ + [new Assert\NotBlank(), new Assert\Type('string')], + 'example2' => [new Assert\Type('string')], + 'example3' => [new Assert\NotBlank(), new Assert\Type('string')], + 'example4' => [new Assert\NotBlank(), new Assert\Type('string')], + ]); + } +} + +?> +----- + [new Assert\NotBlank(), new Assert\Type('string')], + 'example2' => [new Assert\Type('string')], + 'example3' => [new Assert\NotBlank(), new Assert\Type('string')], + 'example4' => [new Assert\NotBlank(), new Assert\Type('string')], + ]); + } +} + +?> diff --git a/rules/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector.php b/rules/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector.php index d1f3ab1a4..6322766de 100644 --- a/rules/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector.php +++ b/rules/Symfony73/Rector/Class_/ConstraintOptionsToNamedArgumentsRector.php @@ -57,6 +57,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->isFirstClassCallable()) { + return null; + } + // Match classes starting with Symfony\Component\Validator\Constraints\ if (! $node->class instanceof FullyQualified && ! $node->class instanceof Name) { return null; @@ -84,6 +88,19 @@ public function refactor(Node $node): ?Node return null; } + $args = $node->getArgs(); + if ($className === 'Symfony\Component\Validator\Constraints\Collection' + && count($args) === 1 + && $args[0]->value instanceof Array_) { + + if ($args[0]->name instanceof Identifier) { + return null; + } + + $args[0]->name = new Identifier('fields'); + return $node; + } + $array = $node->args[0]->value; $namedArgs = [];