Skip to content

[DX] Add RequiredPolyfillInterface to some rule to enable then, once the project is using polyfill package #8368

Closed
rectorphp/rector-src
#5388

Description

@TomasVotruba

E.g. if the project composer.json contains:

{
    "require": {
         "symfony/polyfill-php80": "^1.26",
    }
}

We upgrade to PHP 8.0 features, that benefit from this package. It must be manually checked what Rector rules should be extended, as this polyfill only adds helper for few functions, not all PHP 8.0 features.

To enable such a rule, it must require RequiredPolyfillInterface contract:

class SomeRector implements RequiredPolyfillInterface
{
     public function getPolyfill(): string
    {
         return 'symfony/polyfill-php80';
     }
}

Activity

  1. changed the title [-][DX] Add MinRequiredPolyfillInterface to some rule to enable then, once the project is using polyfill package[/-] [+][DX] Add RequiredPolyfillInterface to some rule to enable then, once the project is using polyfill package[/+] on Dec 18, 2023
  2. fredericgboutin-yapla commented on Apr 22, 2024

    @fredericgboutin-yapla

    This PR is such an underrated feature. You can basically set the PhpVersion to the minimum version your code must support, for example for us it is PHP 7.4. But we seek to migrate to PHP 8.2, so we set the targeted rules to UP_TO_PHP_82.

    One would think that rector would automatically exclude all rules that are not PHP 7.4 compatible, but no. If you use a polyfill like symfony/polyfill-php80, symfony/polyfill-php81 and symfony/polyfill-php82 rector will enable some rules like StrStartsWithRector and StrContainsRector.

    Anyway, thanks for that! Call me impressed. Cheers 👋

  3. TomasVotruba commented on Apr 22, 2024

    @TomasVotruba
    MemberAuthor

    Thank you Frederic for kind words 🙏 Spread the word to help out the community to learn about those features 🥳

  4. github-actions commented on Feb 8, 2026

    @github-actions
    Contributor

    This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

  5. locked as resolved and limited conversation to collaborators on Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions