BrianHenryIE / strauss

Prefix PHP namespaces and classnames to allow multiple versions of libraries to exist without conflict.
https://brianhenryie.github.io/strauss/
MIT License
142 stars 23 forks source link

Strauss replacing strings that looks like class name #112

Open Dartui opened 4 months ago

Dartui commented 4 months ago

Here is a repository that recreates the issue: https://github.com/Dartui/strauss-prefix-error Here is a change that is generated by Strauss: https://github.com/Dartui/strauss-prefix-error/pull/1/files

If you want to test that locally simply clone repository and run composer install.

TL;DR - Strauss replaces string values to the FQCN if it matches the name of the imported class that is used in the same file. Is it possible to exclude this behavior somehow? I've tried using exclude_from_prefix but without success

Dartui commented 3 months ago

For anyone interested - running strauss --updateCallSites=false disables replacements in project files. It does not solve the issue, but for me it resolves my problem.

Feel free to close that issue if there are no plans to take on that.

BrianHenryIE commented 3 months ago

updateCallSites should be false by default. So maybe that’s a bug itself.

To the original issue — I haven’t come up with a way to address it. It is a namespace, and namespaces are correctly required to be replaced in strings, but I don’t know how to disambiguate a namespace from a proper noun when they are the exact same string.

Ideally all projects would use Company\Project style namespaces. As suggested (not required) in PSR-4.

If you have a suggestion on how to tell them apart, let me know.