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.
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/3dd2a727-c594-4fdf-8cc3-b29050c49cfb
Responsible rules
ConstraintOptionsToNamedArgumentsRectorHere’s the Expected Behavior section updated with
example1,example2, etc.:Expected Behavior
Current (incorrect) output:
Expected (correct) output:
Explanation:
The rule
ConstraintOptionsToNamedArgumentsRectorshould convert the array to use the named argumentfields, rather than transforming the array keys directly into named arguments.