-
-
Notifications
You must be signed in to change notification settings - Fork 426
[TypeDeclaration] Make configurable on NarrowObjectReturnTypeRector to allow to not make change return on abstract/interface return #7695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…o allow to not make change return on abstract/interface return
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
|
||
| return static function (RectorConfig $rectorConfig): void { | ||
| $rectorConfig->ruleWithConfiguration(NarrowObjectReturnTypeRector::class, [ | ||
| NarrowObjectReturnTypeRector::IS_ALLOW_ABSTRACT_AND_INTERFACE => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
I just find this option name confusing. Could you name it INCLUDE_STANDALONE_CLASS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means the value need to be true, default false, but "include" term means "also", which a bit contradictive imo.
For better word, I think it can be ALLOW_CONTRACT_RETURN
It is about adding return type which return type is contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include standalone class should be false by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is nothing todo with standalone class or not, it is about returning abstract or interface as return type, whether class extends another class or not, if the method return interface, this config will skip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I've checked the original report again.
In that case we don't need any configuration. That case should be skipped, as it would create breaking code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we had discussion about this on original PR with @Orest-Divintari and @ruudk , the use of replace interface/abstract class to concrete class is valid,
But as @calebdw and @WyriHaximus pointed, there are use case which keep interface/abstract as return type make sense, usually on unit test purpose which still use mock object everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but how do you make a boundary which interface should be replaced and which not? This rule replace e.g. all getRule() in phsptan tests with exact return type of the rule. It doesn't add any value, as parent return type is generic on purpose. It's part of contract.
Once we start adding such configuration, this rule turns into manual labour I want to avoid. This rule should only replace one object type with more specific one. Not all interface types with exact returns, which sparks last 2 reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into this tomorrow. Closing to avoid further configuration on this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common interface type to be skipped:
- Interface return with
Psr\\prefix - Interface return with
Interop\\prefix
Common interface type should be allowed to be replaced:
- Doctrine\Common\Collections\Collection
- PhpParser\Node
This is what I proposed in old PR 3 weeks ago
and closed.
@Orest-Divintari @ruudk @calebdw per our discussion on the original PR:
the contract return was returned, but this cause some issue reported while interface return is valid, see issue:
This PR make it configurable, for allow to skip abstract/interface return, for whatever default value is, this imo should be configurable.
Closes rectorphp/rector#9525