Skip to content

Add PHP types to private methods and functions #49348

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? 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 Add many missing PHPdoc return types #49349)
  • Psalm may not infer the correct set of return types. If an unexpected type is returned, this will result in a PHP error.

nicolas-grekas added a commit that referenced this pull request Feb 13, 2023
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
@nicolas-grekas nicolas-grekas force-pushed the issue-47551/return-types-php branch from 02325f2 to 384c9a6 Compare February 13, 2023 09:15
@nicolas-grekas
Copy link
Member

Thank you @wouterj.

@nicolas-grekas nicolas-grekas merged commit 394ae7f into symfony:6.3 Feb 13, 2023
@wouterj wouterj deleted the issue-47551/return-types-php branch February 13, 2023 09:45
nicolas-grekas added a commit that referenced this pull request Mar 2, 2023
…(fancyweb)

This PR was merged into the 6.3 branch.

Discussion
----------

[TwigBridge] Fix TwigDataCollector::getTime() return type

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

Ref #49348

It generates implicit incompatible float to int conversion deprecations.

Commits
-------

29e2e13 [TwigBridge] Fix TwigDataCollector::getTime() return type
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.

3 participants