rector-symfony icon indicating copy to clipboard operation
rector-symfony copied to clipboard

Order of optional parameters

Open florisluiten opened this issue 2 months ago • 6 comments

Expected output and potential fix for issue with InvokableCommandInputAttributeRector

florisluiten avatar Dec 09 '25 12:12 florisluiten

@samsonasik Could you look into this?

TomasVotruba avatar Dec 09 '25 13:12 TomasVotruba

I will try

samsonasik avatar Dec 09 '25 13:12 samsonasik

@florisluiten I've updated the rule, so it can keep correct attribute per line formatting. Hopefully it will fix the comma issue. Can you rebase?

TomasVotruba avatar Dec 11 '25 23:12 TomasVotruba

Hi guys, thanks for helping me out here.

I rebased on master and cherry-picked the commits. However, the tests still fail with the trailing comma's. Did I perhaps do something wrong?

I did notice that in one situation, the comma between parameters is missing as well:

9) Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\InvokableCommandInputAttributeRectorTest::test with data set #13 ('/[...].php.inc
')                                                                                             
Failed on fixture file "with_multiple_arguments_options_fluent.php.inc"
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@                                                                                                                                                                                         
         #[\Symfony\Component\Console\Attribute\Argument(name: 'argument2', description: 'Argument2 description')]
         string $argument2,                                                                                                                                                                   
         #[\Symfony\Component\Console\Attribute\Option(name: 'option1', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option1 description')]
-        bool $option1 = false,
+        bool $option1 = false
         #[\Symfony\Component\Console\Attribute\Option(name: 'option2', shortcut: 'p', mode: InputOption::VALUE_NONE, description: 'Option2 description')]
-        bool $option2 = false     
+        bool $option2 = false,
     ): int                                                                                                                                                                                   
     {     

So I must conclude that my original thought that these comma's were automatically applied is incorrect. I'm now trying to read into how this all works, hoping that better understanding makes debugging easier.

florisluiten avatar Dec 19 '25 08:12 florisluiten

On the middle params, comma is needed. To debug, you probably needs to create temporary variable, the clear up params, then add one by one params on sort.

samsonasik avatar Dec 19 '25 08:12 samsonasik

Thanks for the pointers! I'm a couple of hours later into this thing and I still haven't figured out how to do this... I give up :disappointed:

florisluiten avatar Dec 19 '25 12:12 florisluiten