Search code examples
coding-stylephpstorm

PhpStorm code reformatter treatment of semi-colons


I write:

$loggedInUser = new User();
$loggedInUser
    ->setFirstName("John")
    ->setLastName("Doe")
    ->setAge(42)
;

When I invoke PhpStorm's code reformatter, it moves the ; character up, and gives:

$loggedInUser = new User();
$loggedInUser
    ->setFirstName("John")
    ->setLastName("Doe")
    ->setAge(42);

Is there a way to make it use the first style, with the semi-colon in its own line, or at least not re-format it?

I looked through all the code-style settings and couldn't find anything that looked relevant, but maybe I missed some style definition, or a separate setting.

I am aware of the // @formatter:off technique, but I don't want to litter my code with it.


Solution

  • Please ensure that Chained method calls | Place ';' on new line option is checked:

    1. Settings / Preferences
    2. Editor | Code Style | PHP | Wrapping and Braces

    enter image description here

    NOTE: Currently it does not seem to work properly when such chaining is used in return statement (watch WI-34152 ticket for that).