Skip to content

Skip MethodChainingNewlineFixer in boolean and comparison chains - #90

Merged
TomasVotruba merged 2 commits into
mainfrom
skip-method-chain-newline-in-boolean-comparison
Sep 29, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
skip-method-chain-newline-in-boolean-comparison

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes #49

MethodChainingNewlineFixer newlined any single-line )->method() chain, including ones used as boolean or comparison operands. This split readable conditions like:

if (
    $paramType->isInteger()->yes()
    || $paramType->isBoolean()->yes()
) {

into an uglier form with ->yes() pushed onto its own line.

Change

  • ChainMethodCallAnalyzer::isPartOfBooleanOrComparison() scans left and right from the -> at the chain's own bracket depth (skips nested ()/[], stops at the enclosing bracket, ;, {, }). Returns true when a boolean (&&, ||, and, or, xor) or comparison (===, !==, ==, !=, <=>, <=, >=, <, >) operator sits at that depth.
  • MethodChainingNewlineFixer skips the newline when the chain is such an operand.

Plain chains, assignments, and arg/array chains are unaffected - still newlined as before.

Added two skip fixtures covering both examples from the issue.

@TomasVotruba
TomasVotruba force-pushed the skip-method-chain-newline-in-boolean-comparison branch from 39d596f to b2e36a3 Compare September 29, 2026 08:25
@TomasVotruba
TomasVotruba enabled auto-merge (squash) September 29, 2026 08:25
@TomasVotruba
TomasVotruba merged commit f2cb33e into main Sep 29, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the skip-method-chain-newline-in-boolean-comparison branch September 29, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MethodChainingNewlineFixer turns code unreadable

1 participant