phpdoc_separation.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ==========================
  2. Rule ``phpdoc_separation``
  3. ==========================
  4. Annotations in PHPDoc should be grouped together so that annotations of the same
  5. type immediately follow each other. Annotations of a different type are
  6. separated by a single blank line.
  7. Configuration
  8. -------------
  9. ``groups``
  10. ~~~~~~~~~~
  11. Sets of annotation types to be grouped together. Use ``*`` to match any tag
  12. character.
  13. Allowed types: ``list<list<string>>``
  14. Default value: ``[['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['deprecated', 'link', 'see', 'since']]``
  15. ``skip_unlisted_annotations``
  16. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. Whether to skip annotations that are not listed in any group.
  18. Allowed types: ``bool``
  19. Default value: ``false``
  20. Examples
  21. --------
  22. Example #1
  23. ~~~~~~~~~~
  24. *Default* configuration.
  25. .. code-block:: diff
  26. --- Original
  27. +++ New
  28. <?php
  29. /**
  30. * Hello there!
  31. *
  32. * @author John Doe
  33. + *
  34. * @custom Test!
  35. *
  36. * @throws Exception|RuntimeException foo
  37. + *
  38. * @param string $foo
  39. + * @param bool $bar Bar
  40. *
  41. - * @param bool $bar Bar
  42. * @return int Return the number of changes.
  43. */
  44. Example #2
  45. ~~~~~~~~~~
  46. With configuration: ``['groups' => [['deprecated', 'link', 'see', 'since'], ['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['param', 'return']]]``.
  47. .. code-block:: diff
  48. --- Original
  49. +++ New
  50. <?php
  51. /**
  52. * Hello there!
  53. *
  54. * @author John Doe
  55. + *
  56. * @custom Test!
  57. *
  58. * @throws Exception|RuntimeException foo
  59. + *
  60. * @param string $foo
  61. - *
  62. * @param bool $bar Bar
  63. * @return int Return the number of changes.
  64. */
  65. Example #3
  66. ~~~~~~~~~~
  67. With configuration: ``['groups' => [['author', 'throws', 'custom'], ['return', 'param']]]``.
  68. .. code-block:: diff
  69. --- Original
  70. +++ New
  71. <?php
  72. /**
  73. * Hello there!
  74. *
  75. * @author John Doe
  76. * @custom Test!
  77. + * @throws Exception|RuntimeException foo
  78. *
  79. - * @throws Exception|RuntimeException foo
  80. * @param string $foo
  81. - *
  82. * @param bool $bar Bar
  83. * @return int Return the number of changes.
  84. */
  85. Example #4
  86. ~~~~~~~~~~
  87. With configuration: ``['groups' => [['ORM\\*'], ['Assert\\*']]]``.
  88. .. code-block:: diff
  89. --- Original
  90. +++ New
  91. <?php
  92. /**
  93. * @ORM\Id
  94. + * @ORM\GeneratedValue
  95. *
  96. - * @ORM\GeneratedValue
  97. * @Assert\NotNull
  98. - *
  99. * @Assert\Type("string")
  100. */
  101. Example #5
  102. ~~~~~~~~~~
  103. With configuration: ``['skip_unlisted_annotations' => true]``.
  104. .. code-block:: diff
  105. --- Original
  106. +++ New
  107. <?php
  108. /**
  109. * Hello there!
  110. *
  111. * @author John Doe
  112. + *
  113. * @custom Test!
  114. *
  115. * @throws Exception|RuntimeException foo
  116. * @param string $foo
  117. - *
  118. * @param bool $bar Bar
  119. * @return int Return the number of changes.
  120. */
  121. Rule sets
  122. ---------
  123. The rule is part of the following rule sets:
  124. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  125. ``['groups' => [['Annotation', 'NamedArgumentConstructor', 'Target'], ['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['deprecated', 'link', 'see', 'since']]]``
  126. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  127. ``['groups' => [['Annotation', 'NamedArgumentConstructor', 'Target'], ['author', 'copyright', 'license'], ['category', 'package', 'subpackage'], ['property', 'property-read', 'property-write'], ['deprecated', 'link', 'see', 'since']]]``
  128. References
  129. ----------
  130. - Fixer class: `PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSeparationFixer <./../../../src/Fixer/Phpdoc/PhpdocSeparationFixer.php>`_
  131. - Test class: `PhpCsFixer\\Tests\\Fixer\\Phpdoc\\PhpdocSeparationFixerTest <./../../../tests/Fixer/Phpdoc/PhpdocSeparationFixerTest.php>`_
  132. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.