Skip to content

[ErrorHandler] Turn return-type annotations into deprecations by default + add mode to turn them into native types #42623

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
Aug 25, 2021

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Aug 18, 2021

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

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 2;
    }

    class_exists($class);
}

Symfony\Component\ErrorHandler\DebugClassLoader::checkClasses();

@nicolas-grekas nicolas-grekas added this to the 5.4 milestone Aug 18, 2021
@nicolas-grekas nicolas-grekas force-pushed the enable-debugclassloader branch 2 times, most recently from 87fa7a8 to f6bc9ad Compare August 18, 2021 12:24
@nicolas-grekas nicolas-grekas changed the title [ErrorHandler] make DebugClassLoader throw deprecations on missing return types [ErrorHandler] Turn return-type annotations into deprecations by default, add mode to turn them into native types Aug 18, 2021
@nicolas-grekas nicolas-grekas changed the title [ErrorHandler] Turn return-type annotations into deprecations by default, add mode to turn them into native types [ErrorHandler] Turn return-type annotations into deprecations by default + add mode to turn them into native types Aug 18, 2021
@nicolas-grekas nicolas-grekas force-pushed the enable-debugclassloader branch 3 times, most recently from 80c5ef4 to 1269f85 Compare August 25, 2021 08:29
@nicolas-grekas
Copy link
Member Author

/cc @symfony/mergers reviews pending 🙏

@nicolas-grekas nicolas-grekas force-pushed the enable-debugclassloader branch from 1269f85 to 3319eee Compare August 25, 2021 10:10
…ult, add mode to turn them into native types
@nicolas-grekas nicolas-grekas force-pushed the enable-debugclassloader branch from 3319eee to bb11e62 Compare August 25, 2021 13:37
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.

5 participants