Skip to content

Instantly share code, notes, and snippets.

@matyo91
Forked from pgrimaud/phpstorm-autoformat.md
Last active December 12, 2017 13:44
Show Gist options
  • Save matyo91/d4f7e34fbe8eb67b02d7e93c609eadbd to your computer and use it in GitHub Desktop.
Save matyo91/d4f7e34fbe8eb67b02d7e93c609eadbd to your computer and use it in GitHub Desktop.
Autoformat assignments and equals on PHP Storm

Autoformat code : Cmd + Alt + L

##For equals :

Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> Align consecutive assignments

This will replace

$toto = 'test';
$longtoto = 'test';

By :

$toto     = 'test';
$longtoto = 'test';

Settings -> Editor -> Code Style -> Javascript -> Other -> Align with multiple 'var' statements and assignments

This will replace

var myLink = {
    img: "btn.gif",
    text: "Button",
    width: 128
  },
  local = true,
  initial = -1;
var selector = "#id";

var color = "red";
var offset = 10;

By :

var myLink   = {
      img: "btn.gif",
      text: "Button",
      width: 128
    },
    local    = true,
    initial  = -1;
var selector = "#id";

var color  = "red";
var offset = 10;

##For assignments :

Settings -> Editor -> Code Style -> PHP -> Other -> Align key-value pairs

This will replace

$array = [
  'toto' => 'test',
  'longtoto' => 'test'
];

By :

$array = [
  'toto'     => 'test',
  'longtoto' => 'test'
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment