How does PhpStorm determine the namespace of a given directory?
Our project uses Composer and PSR-4.
{
"autoload": {
"psr-4": {
"App\\": "src/App/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
}
}PhpStorm is unable to understand that tests/Application directory corresponds to \App\Tests\Application namespace and, instead, will attempt to use namespace \Application everywhere (Create New PHP Class dialogue, Refactor/ Rename, Refactor/ Copy Class…).
I've followed the complete Repair IDE options to no avail.
If I create an empty project with that structure, it works fine. If I copy my project into another directory and remove .git, .idea and vendor directories, it also works fine!
So it must be taking this configuration from somewhere in either my 60,000 project files or some IDE setting.
While trying out random things, I learnt that some of my tests get saved into .idea/Backend.iml and that information is used in the Create New PHP Class dialogue:
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="FooBarDotCom\" />But deleting these lines does not fix anything.
Where do I need to look?
Please sign in to leave a comment.
I think I found a workaround!
.idea/directory (filename can change, but it's the only*.imlfile).<content url="file://$MODULE_DIR$">tag, make sure you have these lines and delete any other lines you may have for the same URLs:<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="App\Tests\" /><sourceFolder url="file://$MODULE_DIR$/src/App" isTestSource="false" packagePrefix="App\" />That fixed it for me. Now, the Create New PHP Class dialogue suggests the correct namespace and (I want to think) refactorings work reliably.
So I think I've probably found a bug, but the project is company code I cannot share so I guess it'll have to be that way.