Skip to content

Incorrect behavior of ConstraintOptionsToNamedArgumentsRector #9686

@sylfabre

Description

@sylfabre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions