Skip to content

PHP: Fix the indent of a method chain after throw or return - #9849

Open
matthiasblaesing wants to merge 2 commits into
apache:masterfrom
matthiasblaesing:pr-9842
Open

matthiasblaesing wants to merge 2 commits into
apache:masterfrom
matthiasblaesing:pr-9842

Conversation

@matthiasblaesing

Copy link
Copy Markdown
Contributor

Method chains after throw and return gained (at least) one indention level to much.

After this change the indention looks like this (the chains are at indention level 2, 8 spaces indented):

function throwMethodChain($factory): void {
    throw Exception::create()
        ->message('a')
        ->code(1);
}

function returnMethodChain1($factory): Exception {
    return Exception::create()
        ->message('a')
        ->code(1);
}

Co-authored-by: Pavel Železný zeleznypa@users.noreply.github.com
Assisted-by: Claude Sonnet 5.5
Closes: #9842
Closes: #9841

zeleznypa and others added 2 commits December 1, 2026 21:55
- apache#9841
- A throw statement is an ExpressionStatement with a ThrowExpression since
  PHP 8.0 support (NETBEANS-4443). visit(ExpressionStatement) added the indent
  of a statement to it, and visit(MethodInvocation) added the indent of the
  chain, so the lines of a chain after throw got the continuation indent twice
- Look through the ThrowExpression when deciding whether the statement adds
  an indent, as is done for a method call statement
- Add unit tests

The change and the tests were written with the help of an AI model and were
not run: the formatter tests were not built or executed, only the changed class
was compiled against the jars of NetBeans 31. The expected files are written
by hand. The author is not a Java developer.

Assisted-by: Claude Sonnet 5.5
@matthiasblaesing matthiasblaesing added this to the NB33 milestone Dec 1, 2026
@matthiasblaesing matthiasblaesing added PHP [ci] enable extra PHP tests (php/php.editor) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Dec 1, 2026
@matthiasblaesing matthiasblaesing changed the title Fix the indent of a method chain after throw or return PHP: Fix the indent of a method chain after throw or return Dec 1, 2026
@zeleznypa

Copy link
Copy Markdown

Hi Matthias,

thank you very much for taking this over and for the extra work: fixing the authorship, finding the same problem with return, and adding tests for both continuation sizes.

I confirmed the return problem on real code (with the help of an AI assistant, Claude): with NetBeans 31 and Continuation Indentation 4, a method chain after return in one of our files moves from 4 to 8 spaces on reformat, exactly like after throw. The second commit looks right to me, because it uses the same isMethodCall check in visit(ReturnStatement). I have not run a build with the fix myself yet.

I am happy with the change, please go ahead and ping the PHP reviewers. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PHP] Formatter indents a method chain after throw twice (8 spaces with Continuation Indentation 4), since throw became an expression in 2020

2 participants