Magnus
Magnus

Reputation: 18738

Make PhpStorm perform case sensitivity consistency check for namespaces and paths?

I am developing a web application using PhpStorm on OSx. I'm using Composer and have PSR-4 autoloading configured in composer.json. Everything is working fine on my development machine, but autoloading breaks when I upload to the production server which runs Linux.

After some troubleshooting it turns out that it's because OSx is using a case insensitive file system, while Linux is using a case sensitive one. And since my namespaces look like this

App\Service\AuthService

while my paths look like this

app/service/AuthService.php

the autoloader can't find the service folder on Linux, because it's looking for Service (with a capital S).

Okay, so I can fix this easily enough by just renaming all folders and class files to use the same cases as my namespaces. But in order to prevent any accidental case inconsistencies in the future, it would be nice if PhpStorm would warn me when I try to use

use App/Foo/Bar/HelloWorld;

while the actual file path is

app/foo/bar/HelloWorld.php

Is there such a setting I can use to have PhpStorm check this automatically, even when I'm developing on a machine with a case insensitive file system?

Upvotes: 7

Views: 2213

Answers (2)

JSowa
JSowa

Reputation: 10572

PHPStorm provides the code inspection hint for it:

  1. Go to the Preferences | Editor | Inspections
  2. Choose section PHP | Code style
  3. Turn on the option Case mismatch in method call or class usage.

It will highlight all the class names which are mistyped.

Upvotes: 3

scipilot
scipilot

Reputation: 7447

This equivalent Java question got an answer which uses a lower-level technique to reconfigure the IDE to treat the filesystem as case-sensitive.

Case sensitive files in IntelliJ Idea on Mac OSX

I have tried it and it does work, not just namespaces but any file that doesn't match in any way (e.g. includes, requires).

But it warns you on boot that you have said the FS is case-sensitive when it's not, and links to this article which has a few warnings/caveats about using this setting incorrectly.

  • PHPStorm: Help > Edit Custom Properties
  • Create the idea.properties file (if prompted)
  • Add idea.case.sensitive.fs=true
  • Restart the IDE

You may see:

Filesystem Case-Sensitivity Mismatch
    The project seems to be located on a case-insensitive file system.
    This does not match the IDE setting (controlled by property "idea.case.sensitive.fs")
    More details. (show balloon)
https://confluence.jetbrains.com/display/IDEADEV/Filesystem+Case-Sensitivity+Mismatch

So I might try it as an option to do a sweep of errors, but perhaps not use it all the time.

Upvotes: 2

Related Questions