Skip to content

Trailing Comma is preserved with FunctionLikeToFirstClassCallableRector resulting in ParseError #9459

@billypoke

Description

@billypoke

Bug Report

Subject Details
Rector version Rector 2.2.5

When the rule is applied and the arguments to the function are replaced by the first class callable ..., the trailing comma is left in place, which results in a syntax error. This would typically result from a code formatter that applies trailing commas to all function argument invocations, such as php-cs-fixer

 ParseError 

  syntax error, unexpected token ","

  at redacted.php:37
     33▕         }
     34▕ 
     35▕         $paymentEntries->each(
     36▕             StripePayments::dispatch(
  ➜  37▕                 ...,
     38▕             ),
     39▕         );
     40▕     }
     41▕ 

Minimal PHP Code Causing Issue

https://getrector.com/demo/b38131f9-cf1c-4b36-8ee0-81bfdf6fa1a9

Expected Behaviour

This rule should remove the trailing comma if it exists when applying this rule

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