[DeadCode] Add RemoveDuplicatedReturnSelfDocblockRector to drop @return docblock duplicating native self/static#8087
Conversation
252ff3b to
4847e7a
Compare
…turn docblock duplicating native self/static return type
4847e7a to
add182e
Compare
|
Your productivity is crazy! 🚀 |
|
Thank you! So is your merge rate 💯 |
|
@TomasVotruba, @samsonasik this is breaking phpstan---
|
|
Our PHPStan didn't notice a thing. Could you send a failing PHPStan demo link?
This rule can be just skipped, that's why it's a separate rule 👍 |
|
The errors I started getting mainly had to do with Larastan and builder/collection generics, and also undefined model attributes errors, because the builder/collection generics were no longer correct
Here's an example on the phpstan playground: Removing the /**
* @template TNew
* @param TNew $value
- * @return $this
* @phpstan-this-out static<TNew>
*/
public function wrap(mixed $value): static
I (or anybody else, and this will absolutely affect Laravel users) shouldn't have to skip this in the first place--- Important A narrower Here's another example where PHPStan requires |
|
Just curious, is this GPT output or do you type all this? It's rather weird to see AI sloop/different style than I used to read from you. I prefer that :) It seems related to @template logic, see: |
This is all me
No, there's other cases for If you're adamant about keeping this rule, then it should be removed from the default set and be made completely optional |
|
Sorry, I just never so many CAPS used by human latelly. This one reports error regardless docblock: https://phpstan.org/r/1792234f-b8cb-4ff3-8ffe-e6c4949ab6fd |
|
@calebdw No error with/without docblock. https://phpstan.org/r/7abe5a21-8d30-4113-aaea-a976b962f60a
|
|
The point is that there SHOULD be an error---the method indicates that the SAME instance should be returned, not a new instance:
Removing
CC: @ondrejmirtes, do you have any thoughts/opinions here? You designed it---should |
|
This rule only removes docblock, it's not related to |
|
Ideally send a failing test case fiture PR, I'm getting lost in this. |



Adds a dedicated DeadCode rule
RemoveDuplicatedReturnSelfDocblockRectorthat removes a@returndocblock when it only duplicates the nativeself/staticreturn type of the current object.This was originally bundled into
ReturnTypeFromStrictFluentReturnRector; moved here so the fluent rule stays focused on adding the return type, while docblock cleanup is a DeadCode concern. The fluent rule is left untouched.Covers
@return $this,@return self,@return static, and@return CurrentClass(the gap vs the existingRemoveUselessReturnTagRectoris mainly@return $this).