A
A
Aleksandr Yurchenko2021-04-25 22:10:49
phpstorm
Aleksandr Yurchenko, 2021-04-25 22:10:49

How to implement array autoformatting in phpStorm?

Hello.

Please tell me how to implement auto-formatting of an array. Hello example, array before formatting:

public function rules()
{
    return [
        'name' => 'required|min:3|max:55',
        'email_test' => 'required|unique:users.email|min:3|max:55|email',
    ];
}

Array after formatting:
public function rules()
{
    return [
        'name'         => 'required|min:3|max:55',
        'email_test'   => 'required|unique:users.email|min:3|max:55|email',
    ];
}


I went through Editor->Code Styles->PHP but couldn't find the right setting...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksandr Yurchenko, 2021-04-25
@yaleksandr89

There is a similar topic , but the information is outdated.
I'm using PhpStorm 2021.1.1 and the item "Align key-value pairs" is not in the "other" tab (it doesn't exist at all), but in the "Wrapping and Braces" tab.
Summing up, in order to implement automatic formatting of indents in an array, you need to go to "Editor"->"Code Style"->"PHP", on the "Wrapping and Braces" tab, go down to the "Array initializer" item and set the "Align key-value" option pairs"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question