Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm php-code indentation

Tags:

phpstorm

I need these chunks of code to be indented properly like this:

$this->render('rights', array(
    'admin' => $admin,
    'editor' => $editor,
    'author' => $author,
));

and widget snippet:

<?php $this->widget('zii.widgets.CMenu', array(
    'items' => array(
        array('label' => 'label', 'url' => 'url')
    )
)); ?>

With default PHPStorm settings it indents this code like this:

$this->render('rights', array(
                             'admin' => $admin,
                             'editor' => $editor,
                             'author' => $author,
                        ));

I went to Settings->Code Style->Wrapping and Braces and changed following options:

  • Array initializer -> Align when multiple (uncheck)
  • Method call arguments -> Align when multiple (uncheck)

The result is:

$this->render('rights', array(
        'admin' => $admin,
        'editor' => $editor,
        'author' => $author,
    ));

Still not the style I want, but that's all I managed to accomplish. Can you please point me to the option I need to change?

like image 514
Rem Zolotykh Avatar asked Jun 03 '11 02:06

Rem Zolotykh


People also ask

How do I beautify PhpStorm?

The dialog appears when you press Ctrl+Alt+Shift+L in the editor of the current file. If you choose Code | Reformat Code from the main menu or press Ctrl+Alt+L , PhpStorm tries to reformat the source code of the specified scope automatically.

What are smart tabs IntelliJ?

IDEA has a “smart tabs” option that you can turn on: If this check box is selected, IntelliJ IDEA inserts tabs for indentation and reformatting, but fine alignment to a necessary column is done only via spaces. This is done in order to preserve visual representation of the source code, when the Tab Size is changed.


3 Answers

Try selecting all the code and clicking : Ctrl + Alt + I
It's auto indentation shortcut ...

like image 84
Naty Avatar answered Sep 21 '22 05:09

Naty


It seems a to be a known issue. Please watch/vote or add your comments there.

like image 34
CrazyCoder Avatar answered Sep 22 '22 05:09

CrazyCoder


I think this will help you in formatting Your code https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/8

like image 41
mercury Avatar answered Sep 19 '22 05:09

mercury