Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add missing return types and enforce return types on all methods #50821

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
Jun 30, 2023

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Jun 29, 2023

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

In 6.3, we enforced return types on all interface methods. We're missing just a handful return types on non-interface methods (all fixed in this PR). As you can see, the added return types are either data collectors or methods introduced by 6.3 features.

In my opinion, we should start to enforce return types on all methods from 6.4 (either as PHPdoc - for resource and to avoid BC breaks - or PHP native declaration).

@carsonbot carsonbot added this to the 6.4 milestone Jun 29, 2023
@wouterj wouterj changed the title Add missing return types and enforce return types on all methods [WIP] Add missing return types and enforce return types on all methods Jun 29, 2023
@wouterj wouterj force-pushed the enforce-all-return-types branch from d17bde8 to 7529f32 Compare June 29, 2023 12:17
@wouterj
Copy link
Member Author

wouterj commented Jun 29, 2023

@nicolas-grekas I'm afraid I need your help with the data collector return types. It sometimes seem to return a Data object and other times a plain value. I can't really reason when a method can return Data. I've fixed the types that caused the tests to fail, but I'm not sure about the untested methods. Can you have a close look at them? 🙏

@wouterj wouterj force-pushed the enforce-all-return-types branch from 7529f32 to 29a8eec Compare June 29, 2023 12:28
@nicolas-grekas
Copy link
Member

What about going with mixed? We changed some of them to return Data instead of the original data because from the pov of a twig template, we can make a Data object behave as the original one. mixed and @return Data|mixed if that makes sense?

@stof
Copy link
Member

stof commented Jun 29, 2023

Data|mixed is still mixed though.

@wouterj wouterj force-pushed the enforce-all-return-types branch from 29a8eec to d700820 Compare June 29, 2023 14:12
@wouterj wouterj force-pushed the enforce-all-return-types branch from d700820 to 7f5270c Compare June 29, 2023 14:12
@wouterj
Copy link
Member Author

wouterj commented Jun 29, 2023

Alright, I did some further testing and it seems like scalar types are kept as-is, while other types become Data when calling cloneVar(). For the data collectors that do $this->cloneVar($this->data), I've updated the non-scalar return types to be Data|array. Seems like that does the trick (at least, to make all tests green).

@wouterj wouterj force-pushed the enforce-all-return-types branch from 7f5270c to 25376c6 Compare June 29, 2023 14:26
@wouterj wouterj changed the title [WIP] Add missing return types and enforce return types on all methods Add missing return types and enforce return types on all methods Jun 29, 2023
@nicolas-grekas nicolas-grekas force-pushed the enforce-all-return-types branch from 7665b3a to 189c3c8 Compare June 30, 2023 09:21
@nicolas-grekas
Copy link
Member

Thank you @wouterj.

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.

4 participants