Skip to content

Narrow existing return types on private/internal/final/test methods #42213

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

Merged
merged 1 commit into from
Aug 10, 2021

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 6.0
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

More progress from #42149

@nicolas-grekas
Copy link
Member Author

(psalm issues are false positives, with a slight code improvement in ef84e66)

@nicolas-grekas nicolas-grekas force-pushed the more-ret-types branch 2 times, most recently from f08a602 to 97e8f39 Compare July 22, 2021 11:50
@nicolas-grekas nicolas-grekas requested a review from xabbuh as a code owner July 22, 2021 11:50
@nicolas-grekas
Copy link
Member Author

PR is ready @symfony/mergers

@nicolas-grekas nicolas-grekas force-pushed the more-ret-types branch 3 times, most recently from e302e94 to b2de6c3 Compare August 9, 2021 12:00
@nicolas-grekas
Copy link
Member Author

PR rebased and ready.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I need to take a nap now 😅

@nicolas-grekas nicolas-grekas merged commit 061bf35 into symfony:6.0 Aug 10, 2021
@nicolas-grekas nicolas-grekas deleted the more-ret-types branch August 10, 2021 10:17
nicolas-grekas added a commit that referenced this pull request Aug 25, 2021
This PR was merged into the 6.0 branch.

Discussion
----------

Add back ``@return` $this` annotations

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

In #42213 I removed those annotations and tried to convinced myself and others that we could do so without loosing too much.

I was about to send a PR to remove all remaining similar annotations. When I reviewed the patch I created for that, I stopped on `ItemInterface::tag()` (which is just an example):
https://github.com/symfony/symfony/blob/444d43fa11990092c53ba54849bb1df36225adcf/src/Symfony/Contracts/Cache/ItemInterface.php#L52-L57

If we remove that annotation on the interface, all implementations will have to deal with the return value of the call to `tag()`. Whereas with ``@return` $this`, the contracts are clear: no need to, implementations are expected to mutate and return the current object. I don't think this would be appropriate in this example.

/cc `@nikic` as this might be some nice food for thoughts to consider adding `$this` as a possible native return type.

Commits
-------

7fafe83 Add back ``@return` $this` annotations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants