-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ErrorHandler] improve parsing of phpdoc by DebugClassLoader #42149
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
d619df9
to
d5f347b
Compare
99a48fb
to
ad03e81
Compare
…thods (nicolas-grekas) This PR was merged into the 6.0 branch. Discussion ---------- Add return type unions to private/internal/final/test methods | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Spotted thanks to progress made on #42149 Commits ------- af7ff7e Add return type unions to private/internal/final/test methods
ad03e81
to
ba4e57e
Compare
PR updated. It now contains a script that parses the source code of PHP 8.1 to extract all new tentative return types. This is used to generate the new internal As you can see, this makes tests fail because we're missing many such annotations. In a next step, we should add the missing annotations and add also the missing |
src/Symfony/Component/ErrorHandler/Resources/TentativeTypes.php
Outdated
Show resolved
Hide resolved
ba4e57e
to
1ddd094
Compare
I'm going on a break for the following 2 weeks and will be mostly AFK. If you want to play locally with it, check it out, empty Then run What is missing here:
The plan I have in mind for Symfony 6 relies heavily on this work. I want to help the community by providing in 5.4 a The plan for the OSS community would then be: turn this on, fix deprecations, plan a major version bump if needed, then allow Symfony 6 in their composer.json file. I fear that allowing Symfony 6.0 right now in OSS libraries might create a huge WTF moment for the community: the day we'll add the return types in our 6.0 branch, we'll potentially break all those libs that allowed We might need a similar approach for public properties btw. Help wanted on all those topics. |
…est methods (nicolas-grekas) This PR was merged into the 6.0 branch. Discussion ---------- Narrow existing return types on private/internal/final/test methods | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - More progress from #42149 Commits ------- d67a927 Narrow existing return types on private/internal/final/test methods
1ddd094
to
7c0eae4
Compare
Deprecations should be fixed by Nyholm/psr7#187, twigphp/Twig#3554, doctrine/collections#280, doctrine/persistence#202, doctrine/orm#8905 and mongodb/mongo-php-library#855 |
3126d88
to
e8a5d5b
Compare
PR is ready. It requires the last two PRs listed above to be green for tests. Psalm/fabbot reports are false positives. |
e8a5d5b
to
73e757e
Compare
f49d877
to
eb72183
Compare
This PR is ready, remaining failures are false positives. |
… (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- Add missing return types to tests/internal/final methods | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Thanks to #42149 again Commits ------- 0f39a0f Add missing return types to tests/internal/final methods
9d8c5e8
to
11a81d3
Compare
11a81d3
to
3a29158
Compare
…cations by default + add mode to turn them into native types (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Turn return-type annotations into deprecations by default + add mode to turn them into native types | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Leverages #42149 We need extensive doc on the topic for sure, a whole new chapter. DebugClassLoader allows patching an app or a lib by going through these steps: - require `symfony/error-handler` if not already there - run `composer install -q --optimize-autoloader` - copy/paste the below script to the root of the app/lib, in `patch-types.php` - run the script with `SYMFONY_PATCH_TYPE_DECLARATIONS='force=phpdoc' php patch-types.php` `SYMFONY_PATCH_TYPE_DECLARATIONS` can be set to: - `'force=phpdoc'` to copy ``@return`` annotations from parent classes, to express that the next major version of that lib is going to add a native return types; - `'force=1'` to turn ``@return`` annotations into native return types, but only on tests/private/final/internal methods; - `'force=2'` to turn ``@return`` annotations into native return types, for all possible methods. ```php <?php if (false === getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) { echo "Please define the SYMFONY_PATCH_TYPE_DECLARATIONS env var when running this script.\n"; exit(1); } $loader = require __DIR__.'/vendor/autoload.php'; Symfony\Component\ErrorHandler\DebugClassLoader::enable(); foreach ($loader->getClassMap() as $class => $file) { switch (true) { case false !== strpos($file = realpath($file), '/vendor/'): case false !== strpos($file, '/src/path-to-exclude/'): // add as many as required continue; } class_exists($class); } Symfony\Component\ErrorHandler\DebugClassLoader::checkClasses(); ``` Commits ------- bb11e62 [ErrorHandler] Turn return-type annotations into deprecations by default, add mode to turn them into native types
The goal of this PR is to improve
DebugClassLoader
to make it able:@return
defines a narrower type than the native return type,ReturnTypeWillChange