kalessil / phpinspectionsea

A Static Code Analyzer for PHP (a PhpStorm/Idea Plugin)
https://plugins.jetbrains.com/plugin/7622?pr=phpStorm
Other
1.45k stars 118 forks source link

comments between else and if (undefined variable suppression) confuses "missing braces" and "empty block" inspections #745

Closed iakoder closed 6 years ago

iakoder commented 6 years ago
<?php

$defined_var = 1;

if ( $defined_var > 5) {
    $defined_var++;
} else if ( $undefined_var < 0) {
    $defined_var++;
}

Correctly reports the undefined variable in the else/if clause.

Suppress for statement.

<?php

$defined_var = 1;

if ( $defined_var > 5) {
    $defined_var++;
} else /** @noinspection PhpUndefinedVariableInspection */
    if ( $undefined_var < 0) {
    $defined_var++;
}

Now you get "Missing or empty conditionals group statement: Wrap constructs' body within a block" and "Statement has empty body"

It's possible to suppress those and now the else/if looks like this:

<?php

$defined_var = 1;

if ( $defined_var > 5) {
    $defined_var++;
}
/** @noinspection MissingOrEmptyGroupStatementInspection */
/** @noinspection PhpStatementHasEmptyBodyInspection */
else /** @noinspection PhpUndefinedVariableInspection */ if ( $undefined_var < 0) {
    $defined_var++;
}

PhpStorm 2017.3.3 EAP Build #PS-173.4301.15, built on January 10, 2018 Licensed to Intacct / Dan Wilks You have a perpetual fallback license for this version Subscription is active until April 6, 2019 JRE: 1.8.0_152-release-1024-b11 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Mac OS X 10.13.2

Php Inspections (EA Extended) 2.3.15.1

kalessil commented 6 years ago

Fixed