phpdoc_to_comment.rst 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ==========================
  2. Rule ``phpdoc_to_comment``
  3. ==========================
  4. Docblocks should only be used on structural elements.
  5. Configuration
  6. -------------
  7. ``allow_before_return_statement``
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. Whether to allow PHPDoc before return statement.
  10. Allowed types: ``bool``
  11. Default value: ``false``
  12. ``ignored_tags``
  13. ~~~~~~~~~~~~~~~~
  14. List of ignored tags (matched case insensitively).
  15. Allowed types: ``list<string>``
  16. Default value: ``[]``
  17. Examples
  18. --------
  19. Example #1
  20. ~~~~~~~~~~
  21. *Default* configuration.
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. $first = true;// needed because by default first docblock is never fixed.
  27. -/** This should be a comment */
  28. +/* This should be a comment */
  29. foreach($connections as $key => $sqlite) {
  30. $sqlite->open($path);
  31. }
  32. Example #2
  33. ~~~~~~~~~~
  34. With configuration: ``['ignored_tags' => ['todo']]``.
  35. .. code-block:: diff
  36. --- Original
  37. +++ New
  38. <?php
  39. $first = true;// needed because by default first docblock is never fixed.
  40. -/** This should be a comment */
  41. +/* This should be a comment */
  42. foreach($connections as $key => $sqlite) {
  43. $sqlite->open($path);
  44. }
  45. /** @todo This should be a PHPDoc as the tag is on "ignored_tags" list */
  46. foreach($connections as $key => $sqlite) {
  47. $sqlite->open($path);
  48. }
  49. Example #3
  50. ~~~~~~~~~~
  51. With configuration: ``['allow_before_return_statement' => true]``.
  52. .. code-block:: diff
  53. --- Original
  54. +++ New
  55. <?php
  56. $first = true;// needed because by default first docblock is never fixed.
  57. -/** This should be a comment */
  58. +/* This should be a comment */
  59. foreach($connections as $key => $sqlite) {
  60. $sqlite->open($path);
  61. }
  62. function returnClassName() {
  63. /** @var class-string */
  64. return \StdClass::class;
  65. }
  66. Rule sets
  67. ---------
  68. The rule is part of the following rule sets:
  69. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  70. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  71. References
  72. ----------
  73. - Fixer class: `PhpCsFixer\\Fixer\\Phpdoc\\PhpdocToCommentFixer <./../../../src/Fixer/Phpdoc/PhpdocToCommentFixer.php>`_
  74. - Test class: `PhpCsFixer\\Tests\\Fixer\\Phpdoc\\PhpdocToCommentFixerTest <./../../../tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php>`_
  75. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.