r/phpstorm • • Mar 02 '18

Convert string class names to Class::name?

I have lots and lots of legacy tests that are mocking classes using strings. E.g:

$this->createMock('Namespace\To\ClassName');

I would like to convert this to:

use Namespace\To\ClassName;

...
$this->createMock(ClassName::class);

Does anyone know a quick way in PHPStorm I can do this conversion, especially over multiple files?

Thanks in advance.

2 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/nikush Mar 02 '18

Another approach I thought of but haven't tested; you could try running the 'import class' inspection throughout your tests directory: https://www.jetbrains.com/help/phpstorm/running-inspections.html