-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add many missing return types #49342
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
Btw, this is a massive PR. Please let me know if, and how, I should split up this one to ease reviews :) |
Thanks for the PR, that was on my list also :) About void, we specifically decided to NOT add them because it would cause needless BC breaks. I think this is still a wise approach and we should stick to it. Of course, adding |
src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/DeprecationGroup.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/DeprecationNotice.php
Outdated
Show resolved
Hide resolved
da68669
to
cfee93a
Compare
I'm thinking about ways to make this PR reviewable. What about keeping all Another idea: split void from other types? Of course only if this doesn't double the amount of work for you. |
As I already split them in commits, I can easily create a PR for each change. Let me close here and open 3 new PRs instead :) |
This PR was merged into the 6.3 branch. Discussion ---------- Add many missing PHPdoc return types | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Ref #47551, continues #49342 | License | MIT | Doc PR | - This PR adds lots of ``@return`` PHPdoc that we missed in the 5.4 branch. These will produce new deprecation warnings, if applications override one of these methods. It will not break backwards compatibility. Adding these PHPdoc in 6.3 already allow the community to test all these annotations for 6 months in stable version, before committing to adding them as PHP types in 7.0. This way, I hope we patch out any wrong type. This PR is done using a slightly modified Psalter script, based on Psalm's type inference. See #49348 for the counter PR adding real PHP types to private, final or internal methods. Commits ------- e23d8be Add missing PHPdoc return types
This PR was merged into the 6.3 branch. Discussion ---------- Add PHP types to private methods and functions | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Ref #47551, continues #49342 | License | MIT | Doc PR | - This PR adds real PHP types to private, internal or final (excluding ``@final``) methods based on Psalm's type inference. Many more return types are missing still, but let's do them in other contributions. This change can result in BC breaks in multiple ways, so we should carefully review the changes: * A method may wrongly be considered "safe" by Psalter. If the method is unsafe (e.g. ``@final``, but not yet real `final`), we should instead add a PHPdoc return type (see #49349) * Psalm may not infer the correct set of return types. If an unexpected type is returned, this will result in a PHP error. Commits ------- 384c9a6 Add PHP types to private methods and functions
…(wouterj) This PR was merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Do not patch return statements in closures | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The type patcher script also fixes some return statements automatically to deal with void/null differences. However, the script is a bit too eager and also patches return statements of closures inside methods: ```php public function something(): void { $someHandler = function (): ?string { if (...) { return null; } }; } ``` Statements like this were patched to `return;`, causing a PHP fatal error. Note: I didn't find any test for the return statement patching, so I also didn't write one for this bug. However, this bug is discovered by our own CI in #49342, so I would say we've covered the fix :) Commits ------- 1779ee1 [ErrorHandler] Do not patch return statements in closures
This PR was merged into the 6.3 branch. Discussion ---------- Add void (PHPdoc) return types | 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. Commits ------- 508ed81 Add void return types
We've purposely skipped adding some return types in the 6.0 branch, but it seems like our tooling has also missed return types. This PR is build using a slightly modified version of Psalter. The added return types are based on Psalm's analysis, so we should verify whether they are all correct.
I've split the contribution in 3 commits:
I propose adding as much PHPdoc return types as possible in 6.3, as this means we have 6 months to receive feedback from the community (whether they are correct) before committing to adding all the types in 7.0.