header_comment.rst 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. Allowed values: ``'comment'`` and ``'PHPDoc'``
  16. Default value: ``'comment'``
  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. Examples
  28. --------
  29. Example #1
  30. ~~~~~~~~~~
  31. With configuration: ``['header' => 'Made with love.']``.
  32. .. code-block:: diff
  33. --- Original
  34. +++ New
  35. <?php
  36. declare(strict_types=1);
  37. +/*
  38. + * Made with love.
  39. + */
  40. +
  41. namespace A\B;
  42. echo 1;
  43. Example #2
  44. ~~~~~~~~~~
  45. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'PHPDoc', 'location' => 'after_open', 'separate' => 'bottom']``.
  46. .. code-block:: diff
  47. --- Original
  48. +++ New
  49. <?php
  50. +/**
  51. + * Made with love.
  52. + */
  53. +
  54. declare(strict_types=1);
  55. namespace A\B;
  56. echo 1;
  57. Example #3
  58. ~~~~~~~~~~
  59. With configuration: ``['header' => 'Made with love.', 'comment_type' => 'comment', 'location' => 'after_declare_strict']``.
  60. .. code-block:: diff
  61. --- Original
  62. +++ New
  63. <?php
  64. declare(strict_types=1);
  65. +/*
  66. + * Made with love.
  67. + */
  68. +
  69. namespace A\B;
  70. echo 1;
  71. Example #4
  72. ~~~~~~~~~~
  73. With configuration: ``['header' => '']``.
  74. .. code-block:: diff
  75. --- Original
  76. +++ New
  77. <?php
  78. declare(strict_types=1);
  79. -/*
  80. - * Comment is not wanted here.
  81. - */
  82. -
  83. namespace A\B;
  84. echo 1;