[TypeDeclaration] Add ReturnTypeFromStrictFluentReturnRector#4890
[TypeDeclaration] Add ReturnTypeFromStrictFluentReturnRector#4890TomasVotruba merged 25 commits intomainfrom
Conversation
|
|
||
| class NonFinalClass | ||
| { | ||
| public function test(): static |
There was a problem hiding this comment.
@staabm when return $this, return static or return self is actually same, see
- https://3v4l.org/U6gfm#v7.0.33 on PHP 7.0
- https://3v4l.org/B61Io#v8.0.29 on PHP 8.0 (support return static)
so the fallback to return self is fine on php 7.x
There was a problem hiding this comment.
I added test for php 7.x add return self instead of static 5e5ba5e
| { | ||
| if (rand(0, 1)) { | ||
| $this->foo = 'foo'; | ||
| return $this; |
There was a problem hiding this comment.
Another test with a return $this and return null case would be great to support nullable
There was a problem hiding this comment.
that's already covered on ReturnUnionTypeRector https://getrector.com/demo/cda3b293-ac7d-4432-83f5-f23cc833a4c1 while return ?static on final class is not needed, that should be ?self, but that will need separate PR for improvement and consideration.
There was a problem hiding this comment.
I created PR:
for nullable $this return on ReturnUnionTypeRector
| new class { | ||
| public function run() | ||
| { | ||
| return $this; |
There was a problem hiding this comment.
Do we need support for return new self() or return new static(); ?
There was a problem hiding this comment.
I think that need separate PR for easier to review ;)
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
Thank you 👏 |
@TomasVotruba @staabm let's add new rule
ReturnTypeFromStrictFluentReturnRectorto add return type onreturn $this;usage.Closes rectorphp/rector#8067