Skip to content

MissingOrEmptyGroupStatement ​

info on by default quick-fix

Group: 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 ​

OptionTypeDefaultEffect
REPORT_EMPTY_BODYbooltrueEnables 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
 */

Released under the MIT License. Rule catalogue modelled on Php Inspections (EA Extended); independent clean-room implementation.