How to exclude WordPress native classes by Regex?
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?
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
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
@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")
@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.