Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm array indentation 8 spaces in stead of 4

Tags:

php

phpstorm

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?

like image 594
Connor Avatar asked Mar 09 '17 13:03

Connor


1 Answers

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

like image 90
oddCat Avatar answered Oct 15 '22 07:10

oddCat