Skip to content
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

How to exclude WordPress native classes by Regex? #1082

Open
nahid opened this issue Nov 3, 2024 · 4 comments
Open

How to exclude WordPress native classes by Regex? #1082

nahid opened this issue Nov 3, 2024 · 4 comments

Comments

@nahid
Copy link

nahid commented Nov 3, 2024

I want to exclude-classes for all the native WordPress classes by Regex? I also tried the given way, but it's not working

Tried these ways

exclude-classes => ['/^WP_/'],

// and

exclude-classes => ['WP_*'],

but these did not work properly. Please help me, how can I do this?

@theofidry
Copy link
Member

I don't really understand what you mean by "nor work properly". Excluding classes does work for sure, there is plenty of tests, so if there is a peculiar broken case it should be possible to get a reproducer.

I recommend you to check https://github.com/humbug/php-scoper/blob/main/docs/further-reading.md#wordpress-support though

@nahid
Copy link
Author

nahid commented Nov 4, 2024

Sorry for not being able to explain it clearly. The exclude-classes function works generally, but it's not working when I use regex. If I want to exclude all classes with the WP_ prefix, how can I achieve that using regex? @theofidry

@hirasso
Copy link

hirasso commented Nov 4, 2024

@theofidry You should really use the package sniccowp/php-scoper-wordpress-excludes for your WordPress excludes, as described in the documentation (though, well hidden under "further reading")

@theofidry
Copy link
Member

@nahid I would need more details than "it is not working", because I simply do not understand what you mean by that. For instance if I have the following specs:

    'Declaration of an excluded class' => SpecWithConfig::create(
        excludeClasses: ['/^NewPhp.+$/'],
        expectedRecordedClasses: [
            ['NewPhp20Interface', 'Humbug\NewPhp20Interface'],
        ],
        spec: <<<'PHP'
            <?php

            interface NewPhp20Interface {}
            ----
            <?php

            namespace Humbug;

            interface NewPhp20Interface
            {
            }
            \class_alias('Humbug\NewPhp20Interface', 'NewPhp20Interface', \false);

            PHP,
    ),

    'Usage of an excluded class' => SpecWithConfig::create(
        excludeClasses: ['/^NewPhp.+$/'],
        spec: <<<'PHP'
            <?php

            class Foo implements NewPhp20Interface {}
            ----
            <?php

            namespace Humbug;

            class Foo implements \NewPhp20Interface
            {
            }

            PHP,
    ),

Both of those passes the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants