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

2

7

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?

Secondly answered 28/2, 2017 at 16:2 Comment(3)
I could be wrong .. but as far as I'm aware such functionality id absent. You may submit Feature Request ticket to PhpStorm's Issue Tracker or/and here (3rd party plugin: github.com/kalessil/phpinspectionsea/issues)Nuthatch
agreed, royal pain. Also beware of MySQL table names and such, they map to a file-system file typically.Dalton
Alternate solution: #20236422Maidenhair
L
3

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.

Lassa answered 7/9, 2022 at 10:17 Comment(0)
M
2

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.

Maidenhair answered 15/9, 2019 at 4:41 Comment(1)
what a headache is this. still here in 2121 :(Aposiopesis

© 2022 - 2024 — McMap. All rights reserved.