method_argument_space.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. ==============================
  2. Rule ``method_argument_space``
  3. ==============================
  4. In method arguments and method call, there MUST NOT be a space before each comma
  5. and there MUST be one space after each comma. Argument lists MAY be split across
  6. multiple lines, where each subsequent line is indented once. When doing so, the
  7. first item in the list MUST be on the next line, and there MUST be only one
  8. argument per line.
  9. Description
  10. -----------
  11. This fixer covers rules defined in PSR2 ¶4.4, ¶4.6.
  12. Configuration
  13. -------------
  14. ``keep_multiple_spaces_after_comma``
  15. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. Whether keep multiple spaces after comma.
  17. Allowed types: ``bool``
  18. Default value: ``false``
  19. ``on_multiline``
  20. ~~~~~~~~~~~~~~~~
  21. Defines how to handle function arguments lists that contain newlines.
  22. Allowed values: ``'ensure_fully_multiline'``, ``'ensure_single_line'`` and ``'ignore'``
  23. Default value: ``'ensure_fully_multiline'``
  24. ``after_heredoc``
  25. ~~~~~~~~~~~~~~~~~
  26. Whether the whitespace between heredoc end and comma should be removed.
  27. Allowed types: ``bool``
  28. Default value: ``false``
  29. Examples
  30. --------
  31. Example #1
  32. ~~~~~~~~~~
  33. *Default* configuration.
  34. .. code-block:: diff
  35. --- Original
  36. +++ New
  37. <?php
  38. -function sample($a=10,$b=20,$c=30) {}
  39. -sample(1, 2);
  40. +function sample($a=10, $b=20, $c=30) {}
  41. +sample(1, 2);
  42. Example #2
  43. ~~~~~~~~~~
  44. With configuration: ``['keep_multiple_spaces_after_comma' => false]``.
  45. .. code-block:: diff
  46. --- Original
  47. +++ New
  48. <?php
  49. -function sample($a=10,$b=20,$c=30) {}
  50. -sample(1, 2);
  51. +function sample($a=10, $b=20, $c=30) {}
  52. +sample(1, 2);
  53. Example #3
  54. ~~~~~~~~~~
  55. With configuration: ``['keep_multiple_spaces_after_comma' => true]``.
  56. .. code-block:: diff
  57. --- Original
  58. +++ New
  59. <?php
  60. -function sample($a=10,$b=20,$c=30) {}
  61. +function sample($a=10, $b=20, $c=30) {}
  62. sample(1, 2);
  63. Example #4
  64. ~~~~~~~~~~
  65. With configuration: ``['on_multiline' => 'ensure_fully_multiline']``.
  66. .. code-block:: diff
  67. --- Original
  68. +++ New
  69. <?php
  70. -function sample($a=10,
  71. - $b=20,$c=30) {}
  72. -sample(1,
  73. - 2);
  74. +function sample(
  75. + $a=10,
  76. + $b=20,
  77. + $c=30
  78. +) {}
  79. +sample(
  80. + 1,
  81. + 2
  82. +);
  83. Example #5
  84. ~~~~~~~~~~
  85. With configuration: ``['on_multiline' => 'ensure_single_line']``.
  86. .. code-block:: diff
  87. --- Original
  88. +++ New
  89. <?php
  90. -function sample(
  91. - $a=10,
  92. - $b=20,
  93. - $c=30
  94. -) {}
  95. -sample(
  96. - 1,
  97. - 2
  98. -);
  99. +function sample($a=10, $b=20, $c=30) {}
  100. +sample(1, 2);
  101. Example #6
  102. ~~~~~~~~~~
  103. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => true]``.
  104. .. code-block:: diff
  105. --- Original
  106. +++ New
  107. <?php
  108. -function sample($a=10,
  109. - $b=20,$c=30) {}
  110. -sample(1,
  111. - 2);
  112. +function sample(
  113. + $a=10,
  114. + $b=20,
  115. + $c=30
  116. +) {}
  117. +sample(
  118. + 1,
  119. + 2
  120. +);
  121. sample('foo', 'foobarbaz', 'baz');
  122. sample('foobar', 'bar', 'baz');
  123. Example #7
  124. ~~~~~~~~~~
  125. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => false]``.
  126. .. code-block:: diff
  127. --- Original
  128. +++ New
  129. <?php
  130. -function sample($a=10,
  131. - $b=20,$c=30) {}
  132. -sample(1,
  133. - 2);
  134. -sample('foo', 'foobarbaz', 'baz');
  135. -sample('foobar', 'bar', 'baz');
  136. +function sample(
  137. + $a=10,
  138. + $b=20,
  139. + $c=30
  140. +) {}
  141. +sample(
  142. + 1,
  143. + 2
  144. +);
  145. +sample('foo', 'foobarbaz', 'baz');
  146. +sample('foobar', 'bar', 'baz');
  147. Example #8
  148. ~~~~~~~~~~
  149. With configuration: ``['after_heredoc' => true]``.
  150. .. code-block:: diff
  151. --- Original
  152. +++ New
  153. <?php
  154. sample(
  155. <<<EOD
  156. foo
  157. - EOD
  158. - ,
  159. + EOD,
  160. 'bar'
  161. );
  162. Rule sets
  163. ---------
  164. The rule is part of the following rule sets:
  165. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  166. ``['on_multiline' => 'ensure_fully_multiline']``
  167. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  168. ``['on_multiline' => 'ensure_fully_multiline']``
  169. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  170. ``['on_multiline' => 'ensure_fully_multiline']``
  171. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
  172. ``['after_heredoc' => true]``
  173. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ with config:
  174. ``['after_heredoc' => true]``
  175. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ with config:
  176. ``['after_heredoc' => true]``
  177. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ with config:
  178. ``['after_heredoc' => true]``
  179. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ with config:
  180. ``['after_heredoc' => true]``
  181. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  182. ``['on_multiline' => 'ensure_fully_multiline']``
  183. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  184. ``['on_multiline' => 'ensure_fully_multiline']``
  185. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  186. ``['on_multiline' => 'ensure_fully_multiline']``
  187. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  188. ``['on_multiline' => 'ignore']``