-
-
Notifications
You must be signed in to change notification settings - Fork 739
Incorrect behavior of ConstraintOptionsToNamedArgumentsRector #9439
Copy link
Copy link
Closed
rectorphp/rector-symfony
#851Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/3dd2a727-c594-4fdf-8cc3-b29050c49cfb
<?php
use Symfony\Component\Validator\Constraints as Assert;
final class DemoFile
{
public function run(bool $param)
{
$constraints = new Assert\Collection([
'example1' => [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')],
]);
}
}Responsible rules
ConstraintOptionsToNamedArgumentsRector
Here’s the Expected Behavior section updated with example1, example2, etc.:
Expected Behavior
Current (incorrect) output:
public function run(bool $param)
{
$constraints = new Assert\Collection(
example1: [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')]
);
}Expected (correct) output:
public function run(bool $param)
{
$constraints = new Assert\Collection(fields: [
'example1' => [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')],
]);
}Explanation:
The rule ConstraintOptionsToNamedArgumentsRector should convert the array to use the named argument fields, rather than transforming the array keys directly into named arguments.
Reactions are currently unavailable