PSR-0 Underscore compatability
Opened this issue · 6 comments
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
Technically the namespace sperator is a constant of the QualifiedName class:
phpactor/lib/Name/QualifiedName.php
Line 9 in 961515a
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.)
The project uses psr-4 and \\ for another autoloaded section of the codebase, so both would need to be supported at the same time
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
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/
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 🙂
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.