Hello PHP-FIG members,
I would like to start a discussion regarding a potential refinement or an allowed alternative in the PER Coding Style (successor to PSR-12), specifically concerning section 5.1 (if, elseif, else).
Currently, the standard strictly requires else and elseif to be on the same line as the closing brace of the previous block:
The Problem: Code Folding & Scannability In modern development environments (JetBrains PhpStorm, VS Code, Sublime Text), the "Code Folding" feature is essential for navigating large files. When a developer collapses an if block following the PSR-12 standard, the else keyword often gets hidden or visually merged into a single line like: if ($expr1) { ... } else {
This makes it difficult to quickly scan the code to see if an alternative logic branch exists without unfolding every block.
The Proposal: I propose to allow (or recommend as an alternative) placing else and elseif on a new line, similar to the Allman style but keeping the opening brace on the same line as the keyword:
Benefits:
Improved Visual Hierarchy: Each logical branch starts on its own line, making the structure clear at a glance.
Better IDE Integration: When the if block is folded, the else or elseif remains clearly visible on the next line, preserving the "map" of the logic.
Consistency: It aligns with how many developers naturally separate distinct logical steps.
I understand that PSR-12 aimed for vertical compactness, but with high-resolution monitors and the heavy use of IDE folding features, the "saved line" often comes at the cost of readability.
I would love to hear the community's thoughts on whether the PER Coding Style could be updated to allow this formatting as a valid alternative.
Best regards, Amanzhol Zhaparov
Benefits:
Improved Visual Hierarchy: Each logical branch starts on its own line, making the structure clear at a glance.
Better IDE Integration: When the if block is folded, the else or elseif remains clearly visible on the next line, preserving the "map" of the logic.
Consistency: It aligns with how many developers naturally separate distinct logical steps.
I understand that PSR-12 aimed for vertical compactness, but with high-resolution monitors and the heavy use of IDE folding features, the "saved line" often comes at the cost of readability.
I would love to hear the community's thoughts on whether the PER Coding Style could be updated to allow this formatting as a valid alternative.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/php-fig/cb762a86-90a3-4192-b80c-c1627be4255bn%40googlegroups.com.