2072 / PHP-Indenting-for-VIm

The official VIm indent script for PHP
http://www.2072productions.com/to/phpindent.txt
128 stars 29 forks source link

indent for chained #59

Closed zcodes closed 6 years ago

zcodes commented 7 years ago
<?php

// if code with chained function call, and the code in
// the begining of the file, the code will be indent like this.
$user->hello()
->world();

// but below code will indent like this
function hello() {
    $user->hello()
        ->world();
}

// and same code will be indent not like code at the begining.
$user->hello()
    ->world();

// also, if code like this
$user->where([
    'xxx' => 'yyy',
])
->will()
->not()
->indent_here();
// no indent here ...
zcodes commented 7 years ago

I fixed this issue by adding some code, see 549263acc, but this is hacky.

2072 commented 6 years ago

@zcodes thanks for your attempted fix. It was a bit more complex though. This should be fixed now. Please try it and tell me how it does.

I close the issue for now but I'll reopen it if necessary.

zcodes commented 6 years ago

@2072 Thank you for your work!

this fix introduced two new problems now!

  1. different indent style

    $user_name_very_long->name()
                    ->age()
                    ->info();
    $user_name_very_long
    ->name()
    ->age()
    ->info();

    i think the better indent for first condition is like this,

    // this is just use a &sw for continuous indent, just like phpstorm, sublime or other editors
    // different indent style may be cause problem when work in a team.
    //
    // or may be provide an option for configure this ?
    $user_name_very_long->name()
    ->age()
    ->info();
  2. indent error with combined arrow and closure

$query
    ->where(function ($query) {
    $query->where('name', 'user');
    });
2072 commented 6 years ago

Ok this should do it. Please test if everything is all right. Sorry for the delay.