-
-
Notifications
You must be signed in to change notification settings - Fork 739
Incorrect behavior of ConstraintOptionsToNamedArgumentsRector #9686
Copy link
Copy link
Closed
rectorphp/rector-symfony
#924Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | 2.3.8 |
#9439 is not fixed when there are several arguments
Minimal PHP Code Causing Issue
https://getrector.com/demo/7c4f031d-026f-4178-8686-0053975a8439
Before:
<?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')],
], allowExtraFields: false);
}
}
After (incorrect)
{
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 Behaviour
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:
rectorphp/rector-symfony#851 only prevents the bug when there is a single argument.
Using allowExtraFields: false by-passes the fix
Reactions are currently unavailable