fix(member_access): Fix multi line indentation in if clause#901
Open
klausi wants to merge 2 commits intocarthage-software:mainfrom
Open
fix(member_access): Fix multi line indentation in if clause#901klausi wants to merge 2 commits intocarthage-software:mainfrom
klausi wants to merge 2 commits intocarthage-software:mainfrom
Conversation
Contributor
Author
|
Added some more test cases, did not find proper solution yet. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 What Does This PR Do?
Fixes an issue where chained method calls inside control structure conditions (like
ifstatements) were being formatted with incorrect indentation (double indent).🔍 Context & Motivation
When a method chain (e.g.,
$this->foo()->bar()) appeared inside anifcondition, the formatter was applying two levels of indentation: one from the condition wrapper and one from the chain formatter itself. Additionally, heuristics for "short chains" were preventing proper inlining, causing readable code to break awkwardly across multiple lines.This change ensures that chains inside conditions respect the parent indentation context and inline short chains appropriately, matching the expected output in the
if_multiline_operatortest case and general PHP coding standards.This test code:
with settings
is wrongly formatted to:
🛠️ Summary of Changes
is_already_brokenlogic to allow short chains (length <= 3) to be formatted as chains when inside conditions.print_member_access_chainto force inlining of the first access for short chains in conditions, ensuring$object->method()stays together on the first line where possible.📂 Affected Areas
🔗 Related Issues or PRs
📝 Notes for Reviewers
FormatterState.in_conditionto apply these relaxations only where appropriate (insideif(...),while(...), etc.).