phpdoc_align.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. =====================
  2. Rule ``phpdoc_align``
  3. =====================
  4. All items of the given PHPDoc tags must be either left-aligned or (by default)
  5. aligned vertically.
  6. Configuration
  7. -------------
  8. ``align``
  9. ~~~~~~~~~
  10. How comments should be aligned.
  11. Allowed values: ``'left'`` and ``'vertical'``
  12. Default value: ``'vertical'``
  13. ``spacing``
  14. ~~~~~~~~~~~
  15. Spacing between tag, hint, comment, signature, etc. You can set same spacing for
  16. all tags using a positive integer or different spacings for different tags using
  17. an associative array of positive integers ``['tagA' => spacingForA, 'tagB' =>
  18. spacingForB]``. If you want to define default spacing to more than 1 space use
  19. ``_default`` key in config array, e.g.: ``['tagA' => spacingForA, 'tagB' =>
  20. spacingForB, '_default' => spacingForAllOthers]``.
  21. Allowed types: ``int`` and ``array<string, int>``
  22. Default value: ``1``
  23. ``tags``
  24. ~~~~~~~~
  25. The tags that should be aligned. Allowed values are tags with name (``'param',
  26. 'property', 'property-read', 'property-write', 'phpstan-param',
  27. 'phpstan-property', 'phpstan-property-read', 'phpstan-property-write',
  28. 'phpstan-assert', 'phpstan-assert-if-true', 'phpstan-assert-if-false',
  29. 'psalm-param', 'psalm-param-out', 'psalm-property', 'psalm-property-read',
  30. 'psalm-property-write', 'psalm-assert', 'psalm-assert-if-true',
  31. 'psalm-assert-if-false'``), tags with method signature (``'method',
  32. 'phpstan-method', 'psalm-method'``) and any custom tag with description (e.g.
  33. ``@tag <desc>``).
  34. Allowed types: ``list<string>``
  35. Default value: ``['method', 'param', 'property', 'return', 'throws', 'type', 'var']``
  36. Examples
  37. --------
  38. Example #1
  39. ~~~~~~~~~~
  40. *Default* configuration.
  41. .. code-block:: diff
  42. --- Original
  43. +++ New
  44. <?php
  45. /**
  46. - * @param EngineInterface $templating
  47. - * @param string $format
  48. - * @param int $code an HTTP response status code
  49. - * @param bool $debug
  50. - * @param mixed &$reference a parameter passed by reference
  51. + * @param EngineInterface $templating
  52. + * @param string $format
  53. + * @param int $code an HTTP response status code
  54. + * @param bool $debug
  55. + * @param mixed &$reference a parameter passed by reference
  56. *
  57. * @return Foo description foo
  58. *
  59. - * @throws Foo description foo
  60. + * @throws Foo description foo
  61. * description foo
  62. *
  63. */
  64. Example #2
  65. ~~~~~~~~~~
  66. With configuration: ``['align' => 'vertical']``.
  67. .. code-block:: diff
  68. --- Original
  69. +++ New
  70. <?php
  71. /**
  72. - * @param EngineInterface $templating
  73. - * @param string $format
  74. - * @param int $code an HTTP response status code
  75. - * @param bool $debug
  76. - * @param mixed &$reference a parameter passed by reference
  77. + * @param EngineInterface $templating
  78. + * @param string $format
  79. + * @param int $code an HTTP response status code
  80. + * @param bool $debug
  81. + * @param mixed &$reference a parameter passed by reference
  82. *
  83. * @return Foo description foo
  84. *
  85. - * @throws Foo description foo
  86. + * @throws Foo description foo
  87. * description foo
  88. *
  89. */
  90. Example #3
  91. ~~~~~~~~~~
  92. With configuration: ``['align' => 'left']``.
  93. .. code-block:: diff
  94. --- Original
  95. +++ New
  96. <?php
  97. /**
  98. - * @param EngineInterface $templating
  99. - * @param string $format
  100. - * @param int $code an HTTP response status code
  101. - * @param bool $debug
  102. - * @param mixed &$reference a parameter passed by reference
  103. + * @param EngineInterface $templating
  104. + * @param string $format
  105. + * @param int $code an HTTP response status code
  106. + * @param bool $debug
  107. + * @param mixed &$reference a parameter passed by reference
  108. *
  109. * @return Foo description foo
  110. *
  111. - * @throws Foo description foo
  112. + * @throws Foo description foo
  113. * description foo
  114. *
  115. */
  116. Example #4
  117. ~~~~~~~~~~
  118. With configuration: ``['align' => 'left', 'spacing' => 2]``.
  119. .. code-block:: diff
  120. --- Original
  121. +++ New
  122. <?php
  123. /**
  124. - * @param EngineInterface $templating
  125. - * @param string $format
  126. - * @param int $code an HTTP response status code
  127. - * @param bool $debug
  128. - * @param mixed &$reference a parameter passed by reference
  129. + * @param EngineInterface $templating
  130. + * @param string $format
  131. + * @param int $code an HTTP response status code
  132. + * @param bool $debug
  133. + * @param mixed &$reference a parameter passed by reference
  134. *
  135. - * @return Foo description foo
  136. + * @return Foo description foo
  137. *
  138. - * @throws Foo description foo
  139. - * description foo
  140. + * @throws Foo description foo
  141. + * description foo
  142. *
  143. */
  144. Example #5
  145. ~~~~~~~~~~
  146. With configuration: ``['align' => 'left', 'spacing' => ['param' => 2]]``.
  147. .. code-block:: diff
  148. --- Original
  149. +++ New
  150. <?php
  151. /**
  152. - * @param EngineInterface $templating
  153. - * @param string $format
  154. - * @param int $code an HTTP response status code
  155. - * @param bool $debug
  156. - * @param mixed &$reference a parameter passed by reference
  157. + * @param EngineInterface $templating
  158. + * @param string $format
  159. + * @param int $code an HTTP response status code
  160. + * @param bool $debug
  161. + * @param mixed &$reference a parameter passed by reference
  162. *
  163. * @return Foo description foo
  164. *
  165. - * @throws Foo description foo
  166. + * @throws Foo description foo
  167. * description foo
  168. *
  169. */
  170. Rule sets
  171. ---------
  172. The rule is part of the following rule sets:
  173. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  174. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  175. References
  176. ----------
  177. - Fixer class: `PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAlignFixer <./../../../src/Fixer/Phpdoc/PhpdocAlignFixer.php>`_
  178. - Test class: `PhpCsFixer\\Tests\\Fixer\\Phpdoc\\PhpdocAlignFixerTest <./../../../tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php>`_
  179. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.