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

Always exclude the prefix namespace #1098

Open
hirasso opened this issue Dec 27, 2024 · 1 comment
Open

Always exclude the prefix namespace #1098

hirasso opened this issue Dec 27, 2024 · 1 comment
Labels

Comments

@hirasso
Copy link

hirasso commented Dec 27, 2024

Feature Request

The Problem

php-scoper currently scopes already-scoped packages again. Example:

// scoper.inc.php
return [
    'prefix' => 'RH\AdminUtils\Scoped',
];

The result in psr/log after the first run:

namespace RH\AdminUtils\Scoped\Psr\Log;

...after the second run:

namespace RH\AdminUtils\Scoped\RH\AdminUtils\Scoped\Psr\Log;

...after the third run:

namespace RH\AdminUtils\Scoped\RH\AdminUtils\Scoped\RH\AdminUtils\Scoped\Psr\Log;

...and so on. Currently one must add the prefix to exclude-namespaces as well to prevent this behavior:

return [
    'prefix' => 'RH\AdminUtils\Scoped',
    /** prevent double scoping */
    'exclude-namespaces' => ['RH\AdminUtils\Scoped'],
];

The solution

When a prefix is provided, php-scoper should automatically add that namespace to exclude-namespaces.

Considerations

This would of course not work when no custom prefix was provided and php-scoper chooses a random string. But it would be a nice quality-of-live improvement for the case where there is a prefix provided that doesn't change.

@theofidry
Copy link
Member

PHP-Scoper does not re-apply the prefix generally, otherwise a good chunk the specifications would not work at all. Rather, I think the problem is that it does not handle the prefix being a namespace.

I am not sure how easy or hard it is to fix this, but if it is not possible, then I think it's better to fail to clarify its limitation rather than leaving this kind of surprise.

@theofidry theofidry added the bug label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@hirasso @theofidry and others