1.2.409. Empty Blocks

Full empty block, part of a control structures.

It is recommended to remove those blocks, so as to reduce confusion in the code.

<?php

foreach($foo as $bar) ; // This block seems erroneous
    $foobar++;

if ($a === $b) {
    doSomething();
} else {
    // Empty block. Remove this
}

// Blocks containing only empty expressions are also detected
for($i = 0; $i < 10; $i++) {
    ;
}

// Although namespaces are not control structures, they are reported here
namespace A;
namespace B;

?>

1.2.409.1. Connex PHP features

1.2.409.1.1. Suggestions

  • Fill the block with a command

  • Fill the block with a comment that explain the situation

  • Remove the block and its commanding operator

1.2.409.1.2. Specs

Short name

Structures/EmptyBlocks

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Examples

Cleverstyle, PhpIPAM

Available in

Entreprise Edition, Community Edition, Exakat Cloud