Skip to content

ClosureToArrowFunctionRector Should not run if there is a phpstan @var comment in the fucntion #9637

@mbogochow

Description

@mbogochow

Bug Report

Subject Details
Rector version 2.3.5

Minimal PHP Code Causing Issue

Select::make('away_team_id')
      ->label('Away Team')
      ->relationship(
          'awayTeam',
          'name',
          modifyQueryUsing: function (Builder $query) {
              /** @var Builder<Team> $query */
              return $query->inFullNameOrder();
          },
      );

ClosureToArrowFunctionRector changes it to this:

Select::make('away_team_id')
      ->label('Away Team')
      ->relationship(
          'awayTeam',
          'name',
          modifyQueryUsing: 
              /** @var Builder<Team> $query */
              fn(Builder $query) => $query->inFullNameOrder(),
      );

This causes the phpstan type narrowing to no longer apply to $query and there is no way (that I have found) to change the docblock in a way for phpstan to recognize it within an arrow function. I can have phpstan ignore the line instead but I'd rather keep the cleaner approach to avoid ignoring any other issues that might be introduced.

I would like for Rector to skip ClosureToArrowFunctionRector if there is a docblock inside the closure.

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