Rule statement_indentation
¶
Each statement must be indented.
Configuration¶
stick_comment_to_next_continuous_control_statement
¶
Last comment of code block counts as comment for next block.
Allowed types: bool
Default value: false
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
if ($baz == true) {
- echo "foo";
+ echo "foo";
}
else {
- echo "bar";
+ echo "bar";
}
Example #2¶
With configuration: ['stick_comment_to_next_continuous_control_statement' => false]
.
--- Original
+++ New
<?php
- // foo
+// foo
if ($foo) {
echo "foo";
- // this is treated as comment of `if` block, as `stick_comment_to_next_continuous_control_statement` is disabled
+ // this is treated as comment of `if` block, as `stick_comment_to_next_continuous_control_statement` is disabled
} else {
$aaa = 1;
}
Example #3¶
With configuration: ['stick_comment_to_next_continuous_control_statement' => true]
.
--- Original
+++ New
<?php
- // foo
+// foo
if ($foo) {
echo "foo";
- // this is treated as comment of `elseif(1)` block, as `stick_comment_to_next_continuous_control_statement` is enabled
+// this is treated as comment of `elseif(1)` block, as `stick_comment_to_next_continuous_control_statement` is enabled
} elseif(1) {
echo "bar";
} elseif(2) {
- // this is treated as comment of `elseif(2)` block, as the only content of that block
+ // this is treated as comment of `elseif(2)` block, as the only content of that block
} elseif(3) {
$aaa = 1;
- // this is treated as comment of `elseif(3)` block, as it is a comment in the final block
+ // this is treated as comment of `elseif(3)` block, as it is a comment in the final block
}
Rule sets¶
The rule is part of the following rule sets:
@PhpCsFixer with config:
['stick_comment_to_next_continuous_control_statement' => true]
@Symfony with config:
['stick_comment_to_next_continuous_control_statement' => true]
References¶
Fixer class: PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer
Test class: PhpCsFixer\Tests\Fixer\Whitespace\StatementIndentationFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.