statement_indentation.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ==============================
  2. Rule ``statement_indentation``
  3. ==============================
  4. Each statement must be indented.
  5. Configuration
  6. -------------
  7. ``stick_comment_to_next_continuous_control_statement``
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. Last comment of code block counts as comment for next block.
  10. Allowed types: ``bool``
  11. Default value: ``false``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. if ($baz == true) {
  22. - echo "foo";
  23. + echo "foo";
  24. }
  25. else {
  26. - echo "bar";
  27. + echo "bar";
  28. }
  29. Example #2
  30. ~~~~~~~~~~
  31. With configuration: ``['stick_comment_to_next_continuous_control_statement' => false]``.
  32. .. code-block:: diff
  33. --- Original
  34. +++ New
  35. <?php
  36. - // foo
  37. +// foo
  38. if ($foo) {
  39. echo "foo";
  40. - // this is treated as comment of `if` block, as `stick_comment_to_next_continuous_control_statement` is disabled
  41. + // this is treated as comment of `if` block, as `stick_comment_to_next_continuous_control_statement` is disabled
  42. } else {
  43. $aaa = 1;
  44. }
  45. Example #3
  46. ~~~~~~~~~~
  47. With configuration: ``['stick_comment_to_next_continuous_control_statement' => true]``.
  48. .. code-block:: diff
  49. --- Original
  50. +++ New
  51. <?php
  52. - // foo
  53. +// foo
  54. if ($foo) {
  55. echo "foo";
  56. - // this is treated as comment of `elseif(1)` block, as `stick_comment_to_next_continuous_control_statement` is enabled
  57. +// this is treated as comment of `elseif(1)` block, as `stick_comment_to_next_continuous_control_statement` is enabled
  58. } elseif(1) {
  59. echo "bar";
  60. } elseif(2) {
  61. - // this is treated as comment of `elseif(2)` block, as the only content of that block
  62. + // this is treated as comment of `elseif(2)` block, as the only content of that block
  63. } elseif(3) {
  64. $aaa = 1;
  65. - // this is treated as comment of `elseif(3)` block, as it is a comment in the final block
  66. + // this is treated as comment of `elseif(3)` block, as it is a comment in the final block
  67. }
  68. Rule sets
  69. ---------
  70. The rule is part of the following rule sets:
  71. - `@PER <./../../ruleSets/PER.rst>`_
  72. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_
  73. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  74. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  75. - `@PSR2 <./../../ruleSets/PSR2.rst>`_
  76. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  77. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  78. ``['stick_comment_to_next_continuous_control_statement' => true]``
  79. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  80. ``['stick_comment_to_next_continuous_control_statement' => true]``
  81. References
  82. ----------
  83. - Fixer class: `PhpCsFixer\\Fixer\\Whitespace\\StatementIndentationFixer <./../../../src/Fixer/Whitespace/StatementIndentationFixer.php>`_
  84. - Test class: `PhpCsFixer\\Tests\\Fixer\\Whitespace\\StatementIndentationFixerTest <./../../../tests/Fixer/Whitespace/StatementIndentationFixerTest.php>`_
  85. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.