header_comment.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. =======================
  2. Rule ``header_comment``
  3. =======================
  4. Add, replace or remove header comment.
  5. Configuration
  6. -------------
  7. ``header``
  8. ~~~~~~~~~~
  9. Proper header content.
  10. Allowed types: ``string``
  11. This option is required.
  12. ``comment_type``
  13. ~~~~~~~~~~~~~~~~
  14. Comment syntax type.
  15. .. note:: The previous name of this option was ``commentType`` but it is now deprecated and will be removed on next major version.
  16. Allowed values: ``'comment'``, ``'PHPDoc'``
  17. Default value: ``'comment'``
  18. ``location``
  19. ~~~~~~~~~~~~
  20. The location of the inserted header.
  21. Allowed values: ``'after_declare_strict'``, ``'after_open'``
  22. Default value: ``'after_declare_strict'``
  23. ``separate``
  24. ~~~~~~~~~~~~
  25. Whether the header should be separated from the file content with a new line.
  26. Allowed values: ``'both'``, ``'bottom'``, ``'none'``, ``'top'``
  27. Default value: ``'both'``
  28. Examples
  29. --------
  30. Example #1
  31. ~~~~~~~~~~
  32. With configuration: ``['header' => 'Made with love.']``.
  33. .. code-block:: diff
  34. --- Original
  35. +++ New
  36. @@ -1,6 +1,10 @@
  37. <?php
  38. declare(strict_types=1);
  39. +/*
  40. + * Made with love.
  41. + */
  42. +
  43. namespace A\B;
  44. echo 1;
  45. Example #2
  46. ~~~~~~~~~~
  47. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'PHPDoc', 'location' => 'after_open', 'separate' => 'bottom']``.
  48. .. code-block:: diff
  49. --- Original
  50. +++ New
  51. @@ -1,6 +1,10 @@
  52. <?php
  53. +/**
  54. + * Made with love.
  55. + */
  56. +
  57. declare(strict_types=1);
  58. namespace A\B;
  59. echo 1;
  60. Example #3
  61. ~~~~~~~~~~
  62. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'comment', 'location' => 'after_declare_strict']``.
  63. .. code-block:: diff
  64. --- Original
  65. +++ New
  66. @@ -1,6 +1,10 @@
  67. <?php
  68. declare(strict_types=1);
  69. +/*
  70. + * Made with love.
  71. + */
  72. +
  73. namespace A\B;
  74. echo 1;
  75. Example #4
  76. ~~~~~~~~~~
  77. With configuration: ``['header' => '']``.
  78. .. code-block:: diff
  79. --- Original
  80. +++ New
  81. @@ -1,10 +1,6 @@
  82. <?php
  83. declare(strict_types=1);
  84. -/*
  85. - * Comment is not wanted here.
  86. - */
  87. -
  88. namespace A\B;
  89. echo 1;