welovewordpress / SublimePhpTidy

Plugin for Sublime Text 2 to format PHP code to meet the WordPress Coding Standards using a modified version of phptidy
GNU General Public License v2.0
109 stars 30 forks source link

chained methods & anonymous functions & arrays #11

Open tobsn opened 11 years ago

tobsn commented 11 years ago

when I have a lot of chained methods I always break them over and indent once like this:

$class->something( ... )
     ->something( ... )
     ->something( ... )
     ->something( ... )
     ->something( ... )
     ->something( ... );

same applies to anonymous functions:

Class::something( ..., function()
{
     $do->other->stuff( 'here' );
} );

right now it becomes this but it should NOT indent and look like above:

Class::something( ..., function()
     {
          $do->other->stuff( 'here' );
     } );

another issue is indenting of arrays over multiple lines:

$array = function(array(
'something' => 'in here',
'something' => 'in here'
));

right now this happens because of the two round braces, same as with the anonymous function:

$array = function( array(
          'something' => 'in here',
          'something' => 'in here'
     ) );

it should become:

$array = function( array(
     'something' => 'in here',
     'something' => 'in here'
) );

is there any way to get that into the tidy?

thanks! :)

I also added an issue for wp-phptidy: https://github.com/scribu/wp-phptidy/issues/1 and pulled a patch for the indenting of object operators: https://github.com/scribu/wp-phptidy/issues/2


update:

I fixed the -> operator indenting - file: wp-phptidy.php line 1541:

        } elseif (
            isset( $tokens[$key-1] ) and
            is_array( $tokens[$key-1] ) and
            $tokens[$key-1][0] === T_WHITESPACE and
            strpos( $tokens[$key-1][1], "\n" )!==false and
            is_array( $tokens[$key] ) and
            $tokens[$key][0] === T_OBJECT_OPERATOR
        ) {
            $tokens[$key][1] = "\t".$tokens[$key][1];

        } else {