PhpStorm and PSR-12, how can I add it as default coding style?

PhpStorm and PSR-12, how can I add it as default coding style?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Configuring PhpStorm for PSR-12 Compliance

While PSR-12 is technically an extension of PSR-2 and builds upon the foundation laid by PSR-1, it operates as an independent specification designed to cover a broader range of code cases. The PHP-FIG provides this distinction specifically to assist with migration paths, noting that while adherence isn't strictly mandatory, the standard addresses nuances that older configurations often miss. Consequently, relying on legacy defaults can lead to inconsistencies in modern PHP projects.

When opening a project in PhpStorm, you might find yourself staring at a limited dropdown menu of predefined styles. The standard list includes options like "PSR-1" and "PSR-2," but PSR-12 is conspicuously absent. This gap exists because the IDE's built-in presets are static snapshots rather than dynamic reflections of the latest PHP standards. Relying on these defaults means your team will inevitably drift apart stylistically, introducing friction during code reviews and maintenance cycles.

The most common initial reaction to this limitation is attempting to manually define a custom style within the Languages & Frameworks settings. While you can replicate many rules by adjusting indentation, brace placement, and semicolon positioning, this approach carries significant technical debt. Manually configuring every rule creates a fragile setup; if the PSR-12 specification evolves or if the community identifies an edge case requiring clarification, your custom configuration will likely miss these updates unless you manually audit them yourself. Furthermore, sharing a hand-crafted style with a team often requires exporting the entire .idea folder, which is cumbersome and prone to merge conflicts when multiple developers attempt to adopt the same ruleset.

Since there are no dedicated plugins that dynamically inject PSR-12 into the predefined styles list, the solution lies in leveraging PhpStorm's robust import functionality. You can utilize a pre-built XML configuration file provided by the PHP-FIG or generated via command-line tools to bridge this gap.

To implement this without reinventing the wheel, you need to locate a valid phpcs.xml or phpcs.xml.dist file that adheres strictly to PSR-12 rules. Alternatively, you can download the official style configuration from the PHP-FIG repository, which often provides a ready-to-import XML structure for IDEs.

Once you have the configuration file, navigate to your PhpStorm settings (Settings > Languages & Frameworks > PHP). In the "Code Style" section, click the gear icon and select Import.... Browse to your downloaded or generated PSR-12 configuration file. The IDE will parse the XML and populate the style list with a new entry labeled for PSR-12.

This method is superior to manual configuration because it ensures atomic updates. When the specification changes, you simply update the source XML and re-import, guaranteeing your team stays synchronized without needing to audit individual settings. It also allows for seamless sharing; you can distribute the single configuration file alongside your project repository or via a dedicated asset folder, eliminating the need to export entire project configurations for every team member.

By adopting this workflow, you ensure that your codebase adheres to the latest standards while maintaining the flexibility to deviate from specific rules if a particular architectural requirement demands it. The key is treating the style guide as an external dependency rather than a static manual entry, ensuring long-term maintainability and consistency across your development environment.

Our network