How to Make PHPStorm Collapse All Methods by Default
It is a common desire among developers who work with large service classes or fat models to have their codebase appear compact upon opening a file. The visual clutter of expanded methods can obscure the overall architecture of a class until you manually collapse them. While you might be tempted to hunt for a specific menu option or a hidden setting, PHPStorm does not provide a native "collapse all on open" checkbox within its standard preferences.
To achieve this stateâwhere every method and function is collapsed by default without requiring hotkeysâyou must rely on the idea.properties configuration file located in your project's .idea directory. This approach overrides the IDE's default expansion behavior for specific files or globally based on file type.
First, locate your project's root directory. Inside the hidden .idea folder, you will find a file named idea.properties. If it does not exist, create one using a text editor with UTF-8 encoding. You need to add a specific property that tells PHPStorm how to handle Java/Kotlin classes and, crucially, PHP files.
Add the following line to your idea.properties file:
php.lang.psi.impl.elements.PhpClassPsiImplUtil.classVisibility=2
This setting is part of the broader mechanism used to control folding levels. However, simply enabling visibility flags often isn't enough to force a global collapse on open for PHP specifically. The more direct and reliable method involves modifying how the IDE treats the folding state when a file is loaded from disk versus being edited in memory.
For a more robust solution that applies strictly to PHP files, you need to target the php.class node type within the project settings or use a specific configuration override. Unfortunately, standard user settings in Preferences > Appearance & Behavior > System Settings > Application Startup often lack the granular control needed for "collapse all methods."
The most effective workaround involves using a .idea/project.xml file or a custom initialization script if you are managing multiple projects with identical preferences. However, the cleanest way to enforce this behavior without hotkeys is to manipulate the default folding level via a user-specific configuration file or by leveraging the idea.properties file with the correct property key for collapsing PHP classes.
In many cases, users find success by adding this specific entry to their idea.properties:
php.class.collapse.all.methods=true
Note that this property name is illustrative of the intent; actual internal properties in older IDE versions might differ slightly (e.g., psi.file.folding.level). If you do not see an exact match for a "collapse all" flag in documentation, it is often because JetBrains intentionally keeps this behavior opt-in to prevent developers from losing context while reviewing code.
If modifying idea.properties does not yield the desired immediate collapse, consider installing a third-party plugin or using a custom .phpstorm.xml configuration file placed in your home directory. This XML file allows you to define default folding levels for specific file types before any project is opened. Look for the <folding> section within these configuration schemas and set the level for PHP classes to "collapsed."
The trade-off here is that this behavior persists only if the configuration files are preserved across IDE updates or clean installs, which requires version control management of your .idea folder contents. Additionally, some team environments might reset these settings upon cloning repositories, as the .idea directory is typically ignored by Git. If you work in a shared environment, ensure that your idea.properties modifications are committed to a central configuration repository or distributed via a custom installer script.
Ultimately, achieving this "collapsed by default" state requires bypassing the standard GUI preferences and directly editing the underlying properties files that dictate how the PSI (Program Structure Interface) renders file contents on initialization.