plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Function argument formatting discussion

Open mgrip opened this issue 7 years ago • 4 comments

$db->Execute([
    $foo,
    $bar,
    $foobar,
    $somewhatLongParameter,
    $somewhatLongParameterX,
    $somewhatLongParameterXYZ
], $sql, $someOtherArg);

VS

$db->Execute(
  [
      $foo,
      $bar,
      $foobar,
      $somewhatLongParameter,
      $somewhatLongParameterX,
      $somewhatLongParameterXYZ
  ],
  $sql,
  $someOtherArg
);

Vote :+1: on first, Vote :heart: on second


Continuing from https://github.com/prettier/plugin-php/pull/398#discussion_r181853745

@evilebottnawi @czosel @nicoder

mgrip avatar Apr 17 '18 12:04 mgrip

Basically discussing

$db->Execute([
    $foo,
    $bar,
    $foobar,
    $somewhatLongParameter,
    $somewhatLongParameterX,
    $somewhatLongParameterXYZ
], $sql, $someOtherArg);

vs

$db->Execute(
  [
      $foo,
      $bar,
      $foobar,
      $somewhatLongParameter,
      $somewhatLongParameterX,
      $somewhatLongParameterXYZ
  ],
  $sql,
  $someOtherArg
);

We went with the 2nd option in #398, since we followed the same logic from prettierjs. PSR12 docs seem to say that either is acceptable, and seems to leave it up to the developer when to split arguments onto multiple lines vs keep them in a single line. However most of their examples seem to prefer the 1st one

https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#47-method-and-function-calls

mgrip avatar Apr 17 '18 12:04 mgrip

My opinion is that we should follow prettierJS. They already have thought through this logic quite a bit, and from what I can tell it still aligns with PSR12 standards

mgrip avatar Apr 17 '18 12:04 mgrip

@mgrip I think will be better ping something from PSR-12 and ask this question about second example (valid or invalid)

alexander-akait avatar Apr 17 '18 13:04 alexander-akait

  1. In my opinion, if a function call spans multiple lines, then each argument should be on a separate line, for readability. (i.e. option 2)
  2. I'm using a custom PHP_CodeSniffer standard that extends PSR-12, and the code in option 2 is valid.

glen-84 avatar Dec 18 '19 11:12 glen-84