method_argument_space.rst 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. ``after_heredoc``
  15. ~~~~~~~~~~~~~~~~~
  16. Whether the whitespace between heredoc end and comma should be removed.
  17. Allowed types: ``bool``
  18. Default value: ``false``
  19. ``attribute_placement``
  20. ~~~~~~~~~~~~~~~~~~~~~~~
  21. Defines how to handle argument attributes when function definition is multiline.
  22. Allowed values: ``'ignore'``, ``'same_line'`` and ``'standalone'``
  23. Default value: ``'standalone'``
  24. ``keep_multiple_spaces_after_comma``
  25. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. Whether keep multiple spaces after comma.
  27. Allowed types: ``bool``
  28. Default value: ``false``
  29. ``on_multiline``
  30. ~~~~~~~~~~~~~~~~
  31. Defines how to handle function arguments lists that contain newlines.
  32. Allowed values: ``'ensure_fully_multiline'``, ``'ensure_single_line'`` and ``'ignore'``
  33. Default value: ``'ensure_fully_multiline'``
  34. Examples
  35. --------
  36. Example #1
  37. ~~~~~~~~~~
  38. *Default* configuration.
  39. .. code-block:: diff
  40. --- Original
  41. +++ New
  42. <?php
  43. -function sample($a=10,$b=20,$c=30) {}
  44. -sample(1, 2);
  45. +function sample($a=10, $b=20, $c=30) {}
  46. +sample(1, 2);
  47. Example #2
  48. ~~~~~~~~~~
  49. With configuration: ``['keep_multiple_spaces_after_comma' => false]``.
  50. .. code-block:: diff
  51. --- Original
  52. +++ New
  53. <?php
  54. -function sample($a=10,$b=20,$c=30) {}
  55. -sample(1, 2);
  56. +function sample($a=10, $b=20, $c=30) {}
  57. +sample(1, 2);
  58. Example #3
  59. ~~~~~~~~~~
  60. With configuration: ``['keep_multiple_spaces_after_comma' => true]``.
  61. .. code-block:: diff
  62. --- Original
  63. +++ New
  64. <?php
  65. -function sample($a=10,$b=20,$c=30) {}
  66. +function sample($a=10, $b=20, $c=30) {}
  67. sample(1, 2);
  68. Example #4
  69. ~~~~~~~~~~
  70. With configuration: ``['on_multiline' => 'ensure_fully_multiline']``.
  71. .. code-block:: diff
  72. --- Original
  73. +++ New
  74. <?php
  75. -function sample($a=10,
  76. - $b=20,$c=30) {}
  77. -sample(1,
  78. - 2);
  79. +function sample(
  80. + $a=10,
  81. + $b=20,
  82. + $c=30
  83. +) {}
  84. +sample(
  85. + 1,
  86. + 2
  87. +);
  88. Example #5
  89. ~~~~~~~~~~
  90. With configuration: ``['on_multiline' => 'ensure_single_line']``.
  91. .. code-block:: diff
  92. --- Original
  93. +++ New
  94. <?php
  95. -function sample(
  96. - $a=10,
  97. - $b=20,
  98. - $c=30
  99. -) {}
  100. -sample(
  101. - 1,
  102. - 2
  103. -);
  104. +function sample($a=10, $b=20, $c=30) {}
  105. +sample(1, 2);
  106. Example #6
  107. ~~~~~~~~~~
  108. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => true]``.
  109. .. code-block:: diff
  110. --- Original
  111. +++ New
  112. <?php
  113. -function sample($a=10,
  114. - $b=20,$c=30) {}
  115. -sample(1,
  116. - 2);
  117. +function sample(
  118. + $a=10,
  119. + $b=20,
  120. + $c=30
  121. +) {}
  122. +sample(
  123. + 1,
  124. + 2
  125. +);
  126. sample('foo', 'foobarbaz', 'baz');
  127. sample('foobar', 'bar', 'baz');
  128. Example #7
  129. ~~~~~~~~~~
  130. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => false]``.
  131. .. code-block:: diff
  132. --- Original
  133. +++ New
  134. <?php
  135. -function sample($a=10,
  136. - $b=20,$c=30) {}
  137. -sample(1,
  138. - 2);
  139. -sample('foo', 'foobarbaz', 'baz');
  140. -sample('foobar', 'bar', 'baz');
  141. +function sample(
  142. + $a=10,
  143. + $b=20,
  144. + $c=30
  145. +) {}
  146. +sample(
  147. + 1,
  148. + 2
  149. +);
  150. +sample('foo', 'foobarbaz', 'baz');
  151. +sample('foobar', 'bar', 'baz');
  152. Example #8
  153. ~~~~~~~~~~
  154. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'ignore']``.
  155. .. code-block:: diff
  156. --- Original
  157. +++ New
  158. <?php
  159. -function sample(#[Foo] #[Bar] $a=10,
  160. - $b=20,$c=30) {}
  161. -sample(1, 2);
  162. +function sample(
  163. + #[Foo] #[Bar] $a=10,
  164. + $b=20,
  165. + $c=30
  166. +) {}
  167. +sample(1, 2);
  168. Example #9
  169. ~~~~~~~~~~
  170. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'same_line']``.
  171. .. code-block:: diff
  172. --- Original
  173. +++ New
  174. <?php
  175. -function sample(#[Foo]
  176. - #[Bar]
  177. - $a=10,
  178. - $b=20,$c=30) {}
  179. -sample(1, 2);
  180. +function sample(
  181. + #[Foo] #[Bar] $a=10,
  182. + $b=20,
  183. + $c=30
  184. +) {}
  185. +sample(1, 2);
  186. Example #10
  187. ~~~~~~~~~~~
  188. With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'standalone']``.
  189. .. code-block:: diff
  190. --- Original
  191. +++ New
  192. <?php
  193. -function sample(#[Foo] #[Bar] $a=10,
  194. - $b=20,$c=30) {}
  195. -sample(1, 2);
  196. +function sample(
  197. + #[Foo]
  198. + #[Bar]
  199. + $a=10,
  200. + $b=20,
  201. + $c=30
  202. +) {}
  203. +sample(1, 2);
  204. Example #11
  205. ~~~~~~~~~~~
  206. With configuration: ``['after_heredoc' => true]``.
  207. .. code-block:: diff
  208. --- Original
  209. +++ New
  210. <?php
  211. sample(
  212. <<<EOD
  213. foo
  214. - EOD
  215. - ,
  216. + EOD,
  217. 'bar'
  218. );
  219. Rule sets
  220. ---------
  221. The rule is part of the following rule sets:
  222. - `@PER <./../../ruleSets/PER.rst>`_
  223. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_
  224. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  225. ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
  226. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  227. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
  228. ``['after_heredoc' => true]``
  229. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ with config:
  230. ``['after_heredoc' => true]``
  231. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ with config:
  232. ``['after_heredoc' => true]``
  233. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ with config:
  234. ``['after_heredoc' => true]``
  235. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ with config:
  236. ``['after_heredoc' => true]``
  237. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_ with config:
  238. ``['after_heredoc' => true]``
  239. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_ with config:
  240. ``['after_heredoc' => true]``
  241. - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
  242. ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
  243. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  244. ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
  245. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  246. ``['on_multiline' => 'ensure_fully_multiline']``
  247. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  248. ``['on_multiline' => 'ignore']``
  249. References
  250. ----------
  251. - Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixer <./../../../src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php>`_
  252. - Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixerTest <./../../../tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php>`_
  253. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.