Skip to content

Add void (PHPdoc) return types #49347

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
Feb 13, 2023

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Feb 12, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? no
Deprecations? no
Tickets Ref #47551, continues #49342
License MIT
Doc PR -

This introduces lots of void return types to the codebase, following our policy:

  • Adding @return void to any methods that return void is OK
  • Adding void PHP return type is only OK if the method is internal, private or final (excluding @final).

The changes in this PR are automated through a modified Psalter script. We should particularly review if @final classes/methods didn't get real PHP void return types, as this is a BC break.

@derrabus
Copy link
Member

The reason the void return type was left out previously was that it would cause too much trouble downstream for too little gain. I think @nicolas-grekas had a strong case against it.

However, I've been working with other codebases that used the void type consistently and I really like it. If we want to achieve 100% coverage with native return types as I proposed in #47551 (comment), using the void return type on a larger scale becomes inevitable.

👍🏻 from my side. I'll see if I can review the PR soon, but I'll probably do so in multiple sessions because my head will start to spin if I try to review it in one go. 🙈

@derrabus
Copy link
Member

derrabus commented Feb 13, 2023

We should particularly review if @final classes/methods didn't get real PHP void return types, as this is a BC break.

The formatter/handler/processor classes from the Monolog bridge are flagged @final, but native return types have been added there. I believe that this is still okay, but since you mentioned that case explicitly, I wanted to point it out. 🙂

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch from d606983 to 73c34f4 Compare February 13, 2023 09:32
@wouterj
Copy link
Member Author

wouterj commented Feb 13, 2023

I believe that this is still okay, but since you mentioned that case explicitly, I wanted to point it out. slightly_smiling_face

I think our policy is "when flagged with @final, it will be considered final on the next major". I.e. we should not treat them as final in the current major

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch from 73c34f4 to e426cf2 Compare February 13, 2023 09:46
@derrabus
Copy link
Member

I think our policy is "when flagged with @final, it will be considered final on the next major". I.e. we should not treat them as final in the current major

No, that's the case for classes that we annotate with @final since Symfony X.Y. On the next major, we either just remove this the Symfony version from the annotation or actually finalize the class.

With @final without a version, it's more like: "We consider this class to be final and if you extend it, you're on your own."

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch from e426cf2 to 5eef2f4 Compare February 13, 2023 09:56
@nicolas-grekas
Copy link
Member

You might be saying the same thing :)
I verified the patch: no files with @final since ... are patched here, while some with @final are, which is fine since we don't consider this a BC break.

@derrabus
Copy link
Member

To elaborate a bit more on the @final case: I think that to some extend, we can be bold here. If someone knowingly extends a class that the framework considers to be final, they need to expect things to break in a minor release.

For classes flagged as @final since Symfony 6.X the case is different because at the time the developer created a child class our class might not have been documented as final yet.

That being said, we probably should be less reluctant with real final classes in 7.0. They allow us to move faster and force us to think about proper extension points. But that's off-topic for this PR.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

First batch. I'm through with bridges and bundles. 😓

@wouterj
Copy link
Member Author

wouterj commented Feb 13, 2023

In case you missed it, the patch failure in the 8.1 tests is fixed when #49346 is merged (and merged up into 6.3).

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch 3 times, most recently from 1291a58 to ab35772 Compare February 13, 2023 10:32
@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch 4 times, most recently from caf707d to cd171f3 Compare February 13, 2023 11:01
Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Next batch, components Asset - Form.

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch 3 times, most recently from 47eac97 to f1c95be Compare February 13, 2023 11:36
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I pushed some changes (see "force-pushed" links in the Github UI).
All green, ready on my side. 👍

@derrabus
Copy link
Member

We review and patch methods on interfaces (like Symfony\Component\Mime\Header\HeaderInterface::setBody()) in a follow-up, don't we?

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Next batch. I've reviewed all components until Routing + changes done after my last batch.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Last batch. I need a break now. 🤯

@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch from f1c95be to cb352f9 Compare February 13, 2023 13:09
@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-void branch from cb352f9 to 508ed81 Compare February 13, 2023 13:18
@nicolas-grekas
Copy link
Member

We review and patch methods on interfaces (like Symfony\Component\Mime\Header\HeaderInterface::setBody()) in a follow-up, don't we?

Yep, that's what I suggested in #47551 (comment)

@nicolas-grekas
Copy link
Member

Thank you @wouterj.

@nicolas-grekas nicolas-grekas merged commit c6f1328 into symfony:6.3 Feb 13, 2023
@wouterj wouterj deleted the issue-47551/return-types-void branch February 13, 2023 13:34
@wouterj
Copy link
Member Author

wouterj commented Feb 13, 2023

Thank you Nicolas for bringing these raw PRs in good shape in a 4 hour timeframe :)

@wouterj
Copy link
Member Author

wouterj commented Feb 13, 2023

And thanks to Alexander as well for spending a morning looking at : void and @return void :)

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