简体   繁体   中英

PhpStorm array indentation 8 spaces in stead of 4

The code style in PhpStorm has been doing strange things to my array indentation. When creating a new array in a normal way

$array = [|] // The | marks my cursor

Then I press enter

$array = [
        | // My cursor starts all the way there
]

When I reformat my code using CMD + ALT + K , the indentation is reset.

$array = [
    | // To here
]

This happens in every file in my project. I have checked my code style preferences, I have set them to PSR1/PSR2 standard, and have checked every single option that has something to do with indentation/arrays.

This only happens to arrays, not to function declarations, class declarations and control structures.

Is anyone familiar with this problem and if so, is there a solution?

Try this:

1.Go to Preferences -> Code Style -> PHP -> Set from... -> Predefined Style -> allows you to set your code style guidelines to the styles such as PSR-2 and Zend.

2.Go to Code -> Reformat Code -> This option will format all of your code to the code style you set. We recently converted our codebase of around 300,000 lines to the PSR-2 standard. It was done in less than 5 minutes.

Hope this helps. :)

This option is located here:

Settings -> Editor -> Code Style -> PHP

Option name:

Continuation indent:

And change from 8 to 4 .

In case you face the same problem. Make sure to disable your .editorconfig rules as those might conflict with your Predefined Style rules. At Editor > Code Style > EditorConfig , scroll at the bottom and uncheck Enable EditorConfig support .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM