Skip to content

PSR-0 Underscore compatability #2859

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

Open
bchubb-web opened this issue Mar 18, 2025 · 6 comments
Open

PSR-0 Underscore compatability #2859

bchubb-web opened this issue Mar 18, 2025 · 6 comments

Comments

@bchubb-web
Copy link

I work on some legacy projects that use underscore based PSR-0 classnames, e.g

"psr-0": {
    "Foo_": "src/"
},

and the file src/Foo/Bar.php, would have a classname of Foo_Bar, but phpactor suggests it be Bar, and a namespace of Foo

IMO it should take into account the delineating character and suggest namespaces/classnames based on that

@mamazu
Copy link
Contributor

mamazu commented Mar 18, 2025

Technically the namespace sperator is a constant of the QualifiedName class:

private const NAMESPACE_SEPARATOR = '\\';

Can you change that to an underscore and see if that already fixes your problem?
(However this will produce a lot of other issues like e.g. array_split will then also be namespaced.)

@bchubb-web
Copy link
Author

The project uses psr-4 and \\ for another autoloaded section of the codebase, so both would need to be supported at the same time

@dantleech
Copy link
Collaborator

Technically the namespace sperator is a constant of the QualifiedName class:

rather this is to do with class-to-file and the way it determines the class name candidates from file paths:https://github.com/phpactor/class-to-file

@mamazu
Copy link
Contributor

mamazu commented Mar 18, 2025

I would say adding a dependency on composer's namespace mapping every time you want to create a QualifiedName sounds like a big refactoring for this project and most modern codebases wouldn't really benefit from that.

However there are automated tools to help you migrate to namespaces in your project like rector. (last section of the article)
https://tomasvotruba.com/blog/2020/07/06/cleaning-lady-notes-from-class-mess-to-psr4-step-by-step-with-confidence/

@dantleech
Copy link
Collaborator

dantleech commented Mar 18, 2025

I would say adding a dependency on composer's namespace mapping every time you want to create a

it has nothing to do with the QualfiiedName it's just about converting file paths to class names and vice-versa. Class-to-file does not support the _ convention currently 🙂

@mamazu
Copy link
Contributor

mamazu commented Mar 18, 2025

Yeah it seems like it, and it also finds the class if you generate the composer autoloader with authoriative class maps (composer dump-autoload -a). But then you have to run that every time you add a new class. I don't know if that's a good workaround.

ShortName Completion is out of the window then though.

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