Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
99a48fb toad03e81Compare…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#42149Commits-------af7ff7e Add return type unions to private/internal/final/test methods
nicolas-grekas commentedJul 22, 2021
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 |
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedJul 23, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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#42149Commits-------d67a927 Narrow existing return types on private/internal/final/test methods
nicolas-grekas commentedAug 10, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deprecations should be fixed byNyholm/psr7#187,twigphp/Twig#3554,doctrine/collections#280,doctrine/persistence#202,doctrine/orm#8905 andmongodb/mongo-php-library#855 |
3126d88 toe8a5d5bComparenicolas-grekas commentedAug 11, 2021
PR is ready. It requires the last two PRs listed above to be green for tests. Psalm/fabbot reports are false positives. |
f49d877 toeb72183Comparenicolas-grekas commentedAug 17, 2021
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 againCommits-------0f39a0f Add missing return types to tests/internal/final methods
9d8c5e8 to11a81d3Compare…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#42149We 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<?phpif (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
Uh oh!
There was an error while loading.Please reload this page.
The goal of this PR is to improve
DebugClassLoaderto make it able:@returndefines a narrower type than the native return type,ReturnTypeWillChange