Skip to content

Add generics to AbstractRector, RectorInterface and ConfigurableRectorInterface - #8330

Closed
mspirkov wants to merge 4 commits into
rectorphp:mainfrom
mspirkov:improve-abstract-rector
Closed

Add generics to AbstractRector, RectorInterface and ConfigurableRectorInterface#8330
mspirkov wants to merge 4 commits into
rectorphp:mainfrom
mspirkov:improve-abstract-rector

Conversation

@mspirkov

@mspirkov mspirkov commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

I’m developing an extension for Rector and I’ve come across some PHPStan errors:

image

I propose solving this as follows:

  1. Add generics to AbstractRector, RectorInterface, and ConfigurableRectorInterface.
  2. Specify the return type as list for getNodeTypes, since it is essentially always list.

This will also make the code more concise and clear, in my opinion.

@mspirkov
mspirkov marked this pull request as ready for review August 9, 2026 17:07
@mspirkov

mspirkov commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

I see that rector-laravel also has this error, but it’s simply ignored: https://github.com/driftingly/rector-laravel/blob/2636a2af80ecb35fff8dd1e5d67ff939becb2673/phpstan.neon#L23

@TomasVotruba

Copy link
Copy Markdown
Member

Seems too many changes and some of them disabling IDE autocomplete.

Any easier way to automate this?

@mspirkov

Copy link
Copy Markdown
Contributor Author

Seems too many changes

I can add generics to AbstractRector, RectorInterface, and ConfigurableRectorInterface and leave the rest unchanged. This will solve the problem for those who use the maximum PHPStan level, and it won’t cause any inconvenience for others (they’ll be able to continue using @param annotations). Would this option work for you?

some of them disabling IDE autocomplete

Everything works well in VS Code.

image image

Any easier way to automate this?

Unlikely. Generics are usually used in such cases.

@TomasVotruba

TomasVotruba commented Aug 15, 2026

Copy link
Copy Markdown
Member

It breaks PHPStorm autocomplete, as types are gone. I prefer the ignore as Laravel does rather than duplicate same types in docblock and remove type support in IDEs (apart VS Code).

@mspirkov

Copy link
Copy Markdown
Contributor Author

And if I do this using @phpstan annotations and leave all the existing PHPDoc annotations untouched?

@mspirkov

Copy link
Copy Markdown
Contributor Author

Then this would allow me not to ignore PHPStan errors, and I wouldn’t have to write extra annotations everywhere (it would be enough to simply use @extends)

image

@rectorphp rectorphp locked as resolved and limited conversation to collaborators Aug 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants