MissingOrEmptyGroupStatement
info on by default quick-fixGroup: Code style · PhpStorm name: MissingOrEmptyGroupStatementInspection
Control structures should always use a braced block for their body. A body written as a bare statement is easy to break when a second line is added; a braced block that contains nothing is usually leftover or unfinished code.
Example
php
<?php
function demo($flag, $rows, $n) {
if ($flag) log_it();
elseif ($n > 3) $n--;
else $n = 0;
if ($flag) { tick(); }
else if ($n) tock();
foreach ($rows as $row) emit($row);
for ($i = 0; $i < $n; $i++) ;
while (more()) step();
do pull(); while (pending());
}php
<?php
function demo($flag, $rows, $n) {
if ($flag) {
log_it();
}
elseif ($n > 3) {
$n--;
}
else {
$n = 0;
}
if ($flag) { tick(); }
else if ($n) {
tock();
}
foreach ($rows as $row) {
emit($row);
}
for ($i = 0; $i < $n; $i++) {
;
}
while (more()) {
step();
}
do {
pull();
} while (pending());
}Reported:
- line 3: Use a braced block for the body of this construct.
- line 4: Use a braced block for the body of this construct.
- line 5: Use a braced block for the body of this construct.
- line 8: Use a braced block for the body of this construct.
- line 10: Use a braced block for the body of this construct.
- line 11: Use a braced block for the body of this construct.
- line 12: Use a braced block for the body of this construct.
- line 13: Use a braced block for the body of this construct.
Options
| Option | Type | Default | Effect |
|---|---|---|---|
| REPORT_EMPTY_BODY | bool | true | Enables D2 (empty braced bodies). D1 is always on. |
Configure
In custos.json:
json
{
"rules": {
"MissingOrEmptyGroupStatement": {
"enabled": false,
"options": {
"REPORT_EMPTY_BODY": true
}
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore MissingOrEmptyGroupStatement
/**
* @noinspection MissingOrEmptyGroupStatementInspection
*/