header_comment.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. =======================
  2. Rule ``header_comment``
  3. =======================
  4. Add, replace or remove header comment.
  5. Configuration
  6. -------------
  7. ``comment_type``
  8. ~~~~~~~~~~~~~~~~
  9. Comment syntax type.
  10. Allowed values: ``'comment'`` and ``'PHPDoc'``
  11. Default value: ``'comment'``
  12. ``header``
  13. ~~~~~~~~~~
  14. Proper header content.
  15. Allowed types: ``string``
  16. This option is required.
  17. ``location``
  18. ~~~~~~~~~~~~
  19. The location of the inserted header.
  20. Allowed values: ``'after_declare_strict'`` and ``'after_open'``
  21. Default value: ``'after_declare_strict'``
  22. ``separate``
  23. ~~~~~~~~~~~~
  24. Whether the header should be separated from the file content with a new line.
  25. Allowed values: ``'both'``, ``'bottom'``, ``'none'`` and ``'top'``
  26. Default value: ``'both'``
  27. ``validator``
  28. ~~~~~~~~~~~~~
  29. RegEx validator for header content.
  30. Allowed types: ``string`` and ``null``
  31. Default value: ``null``
  32. Examples
  33. --------
  34. Example #1
  35. ~~~~~~~~~~
  36. With configuration: ``['header' => 'Made with love.']``.
  37. .. code-block:: diff
  38. --- Original
  39. +++ New
  40. <?php
  41. declare(strict_types=1);
  42. +/*
  43. + * Made with love.
  44. + */
  45. +
  46. namespace A\B;
  47. echo 1;
  48. Example #2
  49. ~~~~~~~~~~
  50. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'PHPDoc', 'location' => 'after_open', 'separate' => 'bottom']``.
  51. .. code-block:: diff
  52. --- Original
  53. +++ New
  54. <?php
  55. +/**
  56. + * Made with love.
  57. + */
  58. +
  59. declare(strict_types=1);
  60. namespace A\B;
  61. echo 1;
  62. Example #3
  63. ~~~~~~~~~~
  64. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'comment', 'location' => 'after_declare_strict']``.
  65. .. code-block:: diff
  66. --- Original
  67. +++ New
  68. <?php
  69. declare(strict_types=1);
  70. +/*
  71. + * Made with love.
  72. + */
  73. +
  74. namespace A\B;
  75. echo 1;
  76. Example #4
  77. ~~~~~~~~~~
  78. With configuration: ``['header' => 'Made with love.', 'validator' => '/Made with love(?P<EXTRA>.*)??/s', 'comment_type' => 'comment', 'location' => 'after_declare_strict']``.
  79. .. code-block:: diff
  80. --- Original
  81. +++ New
  82. <?php
  83. declare(strict_types=1);
  84. +
  85. /*
  86. * Made with love.
  87. *
  88. * Extra content.
  89. */
  90. +
  91. namespace A\B;
  92. echo 1;
  93. Example #5
  94. ~~~~~~~~~~
  95. With configuration: ``['header' => '']``.
  96. .. code-block:: diff
  97. --- Original
  98. +++ New
  99. <?php
  100. declare(strict_types=1);
  101. -/*
  102. - * Comment is not wanted here.
  103. - */
  104. -
  105. namespace A\B;
  106. echo 1;
  107. References
  108. ----------
  109. - Fixer class: `PhpCsFixer\\Fixer\\Comment\\HeaderCommentFixer <./../../../src/Fixer/Comment/HeaderCommentFixer.php>`_
  110. - Test class: `PhpCsFixer\\Tests\\Fixer\\Comment\\HeaderCommentFixerTest <./../../../tests/Fixer/Comment/HeaderCommentFixerTest.php>`_
  111. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.