6

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?

8
  • Doesn't PHP storm have settings for different types? Commented Mar 9, 2017 at 13:42
  • How about to send a bug report to jetbrains ;-) Commented Mar 9, 2017 at 13:51
  • @Niek What do you mean, exactly? I have checked all code style PHP settings, but I can't find anything that would cause this behaviour. Commented Mar 9, 2017 at 13:51
  • Settings->CodeStyle->PHP->Tabes and Indent There are schemes for default and project check them all. Commented Mar 9, 2017 at 13:55
  • 1
    Did you ever fix this? Commented Mar 5, 2019 at 23:42

4 Answers 4

6

If your file has mixed PHP/HTML content, check your HTML continuation indent under Editor -> Code Style -> HTML -> Tabs and Indents.

Unlike with PHP, it defaults to 8 instead of 4. Change continuation indent to 4, then it will be alright. I changed mine to 4 and now my array declarations look right.

Sign up to request clarification or add additional context in comments.

Comments

5

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. :)

2 Comments

Thanks for the tip. I have reformatted all code in my project, with PSR-2 standards enabled. The problem still persists though, in some files arrays just indent with 8 spaces. If I then reformat the code, it returns to a 4-space indentation. But a new array will be indented with 8 spaces again.
Sorry to hear that, Connor.
0

This option is located here:

Settings -> Editor -> Code Style -> PHP

Option name:

Continuation indent:

And change from 8 to 4.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.