Skip to content

exclude-namespaces matches namespaces that only contain the excluded name #1264

Open

Description

@AdzerKI

Bug report

Question Answer
PHP-Scoper version 0.18.20
PHP version 8.4
Platform with version Ubuntu 24.04

exclude-namespaces matches a name anywhere inside the namespace, not only the namespace itself and its sub-namespaces. NamespaceRegistry::isRegisteredNamespace() uses str_contains(), so excluding Psr also excludes Nyholm\Psr7, and excluding Acme excludes Foo\AcmeBar.

Config:

return [
    'prefix' => 'Vendor',
    'exclude-namespaces' => ['Psr'],
];

With nyholm/psr7 installed, Nyholm\Psr7\Factory\Psr17Factory stays unprefixed while the PSR interfaces are excluded as expected. The docblock and the docs say a name excludes the namespace and its sub-namespaces, so I'd expect Nyholm\Psr7 to be prefixed.

Workaround: a regex, '~^Psr(\\\\|$)~'.

I have a fix with tests ready, will open a PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions