4

Does PSR-12 establish any kind of restriction with method chaining? Are both options below equally valid according to the standard?

Option 1:

$object->methodA()->methodB()->methodC()->methodD();

Option 2:

$object->methodA()
    ->methodB()
    ->methodC()
    ->methodD();
Ernesto Allely
  • 851
  • 10
  • 16
  • Looks like a dupe of https://stackoverflow.com/questions/54623909/php-method-chaining-does-the-psr-specify-arrow-alignment but not much on it either. – Nigel Ren Jul 24 '20 at 15:50
  • It is in fact similar although in my question I specially interested in knowing if multiple methods chained in one line is correct from a PSR-12 perspective. – Ernesto Allely Jul 24 '20 at 16:05
  • 2
    Both correct (because it doesnt specify it) but option 1 can easier cause problems with line lengths https://www.php-fig.org/psr/psr-12/#23-lines. This can be a rule in your own coding standards (additional to psr for example) – blahy Jul 24 '20 at 16:47

0 Answers0