+16

PHP "Reindent Lines"

aalexgabi 7 years ago • updated by Marco Cervellin 6 years ago 1
I am mainly a PHP developer and I'm using Netbeans IDE.

I consider auto-formatting functionality in NetBeans very well done. It indents automatically the entire file, which is desirable all the time because it's well done. The indentation is not only done horizontally but also vertically, meaning more than one empty lines are reduced to one etc.

After some hours struggling I found how to add the keyboard shortcut for the "Reindent Lines" command found in command palette but not in menu:
[code]
[
{ "keys": ["shift+alt+f"], "command": "reindent", "args": {"single_line": false}}
]
[/code]

In PHP I found some problems in Reindent:

I suggest:
- Adding vertical reindentation
- Adding a shortcut key to "Reindent Lines"
- Adding "Reindent Lines" to menu
- Improving "Reindent Lines" by using NetBeans styling rules

Some bugs I found in "Reindent Lines":
[code]
<?php

namespace ens\database;

class DbManager {

    static $connections = array(
        'master' => array(
            'username' => 'root',
            'password' => 'root',
            'dsn' => 'mysql:host=127.0.0.1;dbname=ctc',
            'prefix' => ''
            )
            );
            static $test = array(
                'lala' => 'lolo'
                );
                static function connectAll() {
                    foreach (self::$connections as &$connection)
                    $connection['connection'] = new \ens\database\DbConnection($connection['dsn'], $connection['username'], $connection['password']);
                }
                static function lala($test){

                }

            }
[/code]
That should be something like:
[code]
<?php

namespace ens\database;

class DbManager {

    static $connections = array(
        'master' => array(
            'username' => 'root',
            'password' => 'root',
            'dsn' => 'mysql:host=127.0.0.1;dbname=ctc',
            'prefix' => ''
        )
    );
    static $test = array(
        'lala' => 'lolo'
    );

    static function connectAll() {
        foreach (self::$connections as &$connection)
            $connection['connection'] = new \ens\database\DbConnection($connection['dsn'], $connection['username'], $connection['password']);
    }

    static function lala($test) {
        
    }

}
[/code]
+2

This feature is the only one that prevents me from switching from Netbeans to Sublime Text.

I strongly encourage the improvement of auto formatting for php, html, js and css as they are the main languages in web developement.