Matt Komarnicki
Matt Komarnicki

Reputation: 5432

PHP method chaining: Does the PSR specify arrow alignment?

Is there any strict requirement if chaining should be aligned starting with the class vs. methods only?

Chaining with only methods being aligned:

$this->fooService
    ->doBar()
    ->doBaz();

Above example shows the alignment just within methods.

Chaining with everything being aligned:

$this
    ->fooService
    ->doBar()
    ->doBaz();

This question is not opinion based as I'm asking about coding standard defined by the PHP community.

Upvotes: 6

Views: 1270

Answers (1)

dan webb
dan webb

Reputation: 646

The PSR and PSR 2 do not specify anything regarding method chaining from what I have read. PSR concludes that "interline alignment" is intentionally left out

Upvotes: 4

Related Questions