1.2.642. Lone Blocks

Grouped code without a commanding structure is useless and may be removed.

Blocks are compulsory when defining a structure, such as a class, a function or a switch. They are most often used with flow control instructions, like if then or foreach.

Blocks are also valid syntax that group several instructions together, though they have no effect at all. They are unusual enough to confuse the reader.

Most often, it is a ruin from a previous flow control instruction, whose condition was removed or commented. They should be removed.

<?php

    // Lone block without artefact
    {
     $a = 3;
     $c = 4;
    }

    // Lone block with commented out loop
    //foreach($a as $b)
    {
        $b = 1;
    }
?>

1.2.642.1. Suggestions

  • Remove the useless curly brackets

1.2.642.2. Specs

Short name

Structures/LoneBlock

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

Features

block

Examples

ThinkPHP, Tine20

Available in

Entreprise Edition, Community Edition, Exakat Cloud