phpdoc_order.rst 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. =====================
  2. Rule ``phpdoc_order``
  3. =====================
  4. Annotations in PHPDoc should be ordered in defined sequence.
  5. Configuration
  6. -------------
  7. ``order``
  8. ~~~~~~~~~
  9. Sequence in which annotations in PHPDoc should be ordered.
  10. Allowed types: ``string[]``
  11. Default value: ``['param', 'throws', 'return']``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. /**
  22. * Hello there!
  23. *
  24. - * @throws Exception|RuntimeException foo
  25. * @custom Test!
  26. - * @return int Return the number of changes.
  27. * @param string $foo
  28. * @param bool $bar Bar
  29. + * @throws Exception|RuntimeException foo
  30. + * @return int Return the number of changes.
  31. */
  32. Example #2
  33. ~~~~~~~~~~
  34. With configuration: ``['order' => ['param', 'throws', 'return']]``.
  35. .. code-block:: diff
  36. --- Original
  37. +++ New
  38. <?php
  39. /**
  40. * Hello there!
  41. *
  42. - * @throws Exception|RuntimeException foo
  43. * @custom Test!
  44. - * @return int Return the number of changes.
  45. * @param string $foo
  46. * @param bool $bar Bar
  47. + * @throws Exception|RuntimeException foo
  48. + * @return int Return the number of changes.
  49. */
  50. Example #3
  51. ~~~~~~~~~~
  52. With configuration: ``['order' => ['param', 'return', 'throws']]``.
  53. .. code-block:: diff
  54. --- Original
  55. +++ New
  56. <?php
  57. /**
  58. * Hello there!
  59. *
  60. - * @throws Exception|RuntimeException foo
  61. * @custom Test!
  62. - * @return int Return the number of changes.
  63. * @param string $foo
  64. * @param bool $bar Bar
  65. + * @return int Return the number of changes.
  66. + * @throws Exception|RuntimeException foo
  67. */
  68. Example #4
  69. ~~~~~~~~~~
  70. With configuration: ``['order' => ['param', 'custom', 'throws', 'return']]``.
  71. .. code-block:: diff
  72. --- Original
  73. +++ New
  74. <?php
  75. /**
  76. * Hello there!
  77. *
  78. + * @param string $foo
  79. + * @param bool $bar Bar
  80. + * @custom Test!
  81. * @throws Exception|RuntimeException foo
  82. - * @custom Test!
  83. * @return int Return the number of changes.
  84. - * @param string $foo
  85. - * @param bool $bar Bar
  86. */
  87. Rule sets
  88. ---------
  89. The rule is part of the following rule sets:
  90. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  91. ``['order' => ['param', 'return', 'throws']]``
  92. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  93. ``['order' => ['param', 'return', 'throws']]``