Renaming a PSR Namespace Directory in PhpStorm 2017.1

When you rename a directory that is also part of a PSR-0/4 namespace structure, PhpStorm 2017.1.4 will now rename your namespace to match.

PSR-0 and PSR-4 are a direct 1:1 mapping between namespace levels and folders. Consequently, when you rename a PSR-0/4 directory, you then need to go and change all the namespaces for classes in that folder, to match the new directory structure. Now PhpStorm 2017.1.4 will do the work for you.

rename-psr

This will work only if you’ve marked your directory as a sources root and have informed PhpStorm what the namespace prefix of the sources root is. Find out more about marking directories in this video.

This will work for all files in the renamed directory, plus any sub-folder with files in them, so you can be sure that all your namespaces will be correct when you’ve updated a namespace by renaming the directory.

– Gary & The PhpStorm Team

About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, Newsletter. Bookmark the permalink.
  • http://www.fractalizer.ru Vladislav Rastrusny

    Great news! But is this implemented in 2017.1.4 or in 2017.1.3?

    • Maxim Kolmakov

      It was actually implemented in 2017.1.1 but we’ve mentioned the latest version just for the simplicity.

      • http://jdempster.tumblr.com/ James Dempster

        Can’t see how mentioning the wrong version makes it simpler.

        • Vladimir Luchansky

          We simply expect all users to keep the software up to date in order to have the best experience with it. :-)