Refactor: Move Class to namespace creates undesired import statements

If I attempt to use the Refactor: Move feature to move a class which did not previously have a namespace into one, PhpStorm will automatically add use statements at the top of every file instead of using fully qualified class names.  This is fine in class files, but I don't want my regular php files and pages to have use statements at the top.  I have both of the PHP auto-import settings disabled and it does not affect this behavior. Is there any way to prevent this from happening?

0
3 comments

Hm, I'm not getting an autogenerated use staments with Refactor:Move.

Could you please advise what version are you using & code sample I could use to try?

0
Avatar
Permanently deleted user

Here is my version info.

PhpStorm 2016.2.2
Build #PS-162.2380.11, built on October 24, 2016
JRE: 1.8.0_112-release-287-b3 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

As for sample code, this seems to happen any time you right click a class name where it is defined, and then use the Refactor: Move command to put it in a namespace.

So I could have a class like this.


Foo.php

class Foo {

}

And then a usage of the class in another file.

test.php

$obj = new Foo();

After I perform the move operation with a namespace such as Bar, test.php looks like this.

use Bar\Foo;

$obj = new Foo();

I would prefer that the usages simply be replaced by a fully qualified class name, so I would then end up with.

$obj = new Bar\Foo();

However there seems to be no option that will modify the behavior of Refactor: Move in that way.

0

Thanks for the samples, now I'm getting the same.

Indeed seems like there's no option to configure that. You might want to submit a feature request for this at http://youtrack.jetbrains.com/issues/WI#newissue=yes.

0

Please sign in to leave a comment.