Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm insert current namespace

Tags:

phpstorm

I want the PhpStorm to insert current namespace by default or with a hotkey or with live templates.

Whet I create new Php class ("New | PHP Class" dialog) there is a field for a namespace. Is there a way for it to be filled automatically? It does not look a big deal because in my case a namespace is just directory path (I use composer) starting from src. My search efforts did not give my anything about this at all. Looks like PhpStrom does not have this feauture. But maybe there is some plugin or a hack?

like image 971
FreeLightman Avatar asked Mar 04 '18 15:03

FreeLightman


1 Answers

New | PHP Class dialog should fill the namespace automatically based on the directory where file will be created. If it does not then you have not configured your project properly.

Settings/Preferences | Directories -- ensure that your src folder is marked as Source Root. That's depends on project, of course: for Laravel project you need to map app folder to App\ namespace (typical case).

PhpStorm can also detect source roots from your composer.json settings and can even keep it in sync since 2017.2 version (see https://blog.jetbrains.com/phpstorm/2017/07/configuring-with-composer-in-phpstorm-2017-2/).

Some links to read (official help pages):

  • https://www.jetbrains.com/help/phpstorm/configuring-php-namespaces-in-a-project.html
  • https://www.jetbrains.com/help/phpstorm/configuring-content-roots.html
  • https://www.jetbrains.com/help/phpstorm/directories.html
like image 109
LazyOne Avatar answered Oct 26 '22 19:10

LazyOne