PhpStorm tells me: "Namespace name doesn't match PSR 0/PSR 4 project structure"

PSR-4 namespace roots can specify a prefix which should be configured.

Here is the process:

  1. Find the root of your namespace e.g src.
  2. right click Mark Directory as Sources Root.
  3. Menu -> File -> Settings -> Directories.
  4. Click the pencil icon or p^ next to your Sources Root.
  5. Enter the namespace prefix.

See PHPStorm configuring PHP namespaces


Easier than the last answers:

PHPStorm & Composer settings

Go to the Settings windows: Languages & Frameworks -> PHP -> Composer and then, enable Sync IDE settings with composer.json in order to load the PSR-0 & PSR-4 set up.

PS: PhpStorm 2020.3.2 (Build #PS-203.7148.74, built on January 27, 2021)

I hope it's useful to everyone!

Tags:

Phpstorm