VSCode - PHP - Update namespace and imports of other files after moving class

Viewed 245

Does anyone know if it's possible to configure VSCode to have the following occur after moving a file to another locations?

  • Update the namespace of the class/trait.
  • Update the imports of all other files referencing this file.

For example, let's say I have the following classes in src/app:

src/app/Hello.php

<?php

namespace App;

class Hello {
...
}

src/app/Goodbye.php

<?php

namespace App;

use App\Hello;

class Goodbye {
...
}

I want to move my src/app/Hello.php file into src/app/services/Hello.php. The following should occur:

  • The namespace changes from namespace App to namespace App\Services
  • The import in src/app/Goodbye.php changes from use App\Hello to use App\Services\Hello

So then we will have: src/app/services/Hello.php

<?php

namespace App\Services;

class Hello {
...
}

src/app/Goodbye.php

<?php

namespace App;

use App\Services\Hello;

class Goodbye {
...
}

Can this be done with the PHP Intelephense or PHP Namespace Resolver extension, or by any other means?

0 Answers
Related