Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiline_whitespace_before_semicolons behaves inconsistently with multline conditions #7902

Open
danog opened this issue Mar 21, 2024 · 0 comments
Labels
kind/bug topic/whitespace Indentation, spacing, new lines

Comments

@danog
Copy link
Contributor

danog commented Mar 21, 2024

Bug report

In php-cs-fixer v3.52.1, multiline_whitespace_before_semicolons behaves inconsistently, by sometimes moving the ; from a new line to the previous one in a multiline condition, if new_line_for_chained_calls is specified.

I previously submitted #7897 to add a new strategy that fixes the issue, but given the inconsistency it's not exactly clear to me what is the intended behavior of the new_line_for_chained_calls strategy.

The behavior I need is the one specified in my new_line_for_chained_calls_ignore_rest strategy in the PR, i.e. in multiline calls the comma is moved to a new line, and all other multline expressions are ignored, leaving the comma in its place.

Another acceptable behavior is to move the comma to a new line in all multiline expressions (currently done by another fixing tool in my pipeline).

Code snippet that reproduces the problem

<?php
$object->method1()
    ->method2()
    ->method(3);

foreach ($feedbacks as $k => $feedback) {
    $feedback["answer"] = \array_key_exists($feedback["id"], $answers)
        ? $answers[$feedback["id"]]
        : null
    ;
}

$feedback["answer"] = \array_key_exists($feedback["id"], $answers)
    ? $answers[$feedback["id"]]
    : null
;

Result:

<?php
$object->method1()
    ->method2()
    ->method(3);

foreach ($feedbacks as $k => $feedback) {
    $feedback["answer"] = \array_key_exists($feedback["id"], $answers)
        ? $answers[$feedback["id"]]
        : null;
}

$feedback["answer"] = \array_key_exists($feedback["id"], $answers)
    ? $answers[$feedback["id"]]
    : null
;
@danog danog added the kind/bug label Mar 21, 2024
@Wirone Wirone added the topic/whitespace Indentation, spacing, new lines label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug topic/whitespace Indentation, spacing, new lines
Projects
None yet
Development

No branches or pull requests

2 participants