Menu

#27 Unused code is wrongly detected

Fixed
nobody
None
Medium
Defect
2012-02-13
2012-02-09
Anonymous
No

Originally created by: Daniel...@gmail.com

Test code:
<?php
function unusedCodeProblem1() {
    echo "1";
    return;
    echo "2";
}
function unusedCodeProblem2($a) {
    if ($a) return;
    echo "3";
    echo "4";
}
?>

Actual output (I removed docBlocks warnings from the output):
$ php run.php --src test.php --format console
test.php WARNING Line:8 - The statement 'if' must contain its code within a {} block.
test.php WARNING Line:8 - function '%s' has unused code after the return.

Expected output 1:
There should be a warning "WARNING Line:4 ... unused code after return". (echo "2" is unused.)

Expected output 2:
There should NOT be a warning "WARNING Line:8 ... unused code after return". (echo "3" is used.)

SVN [r96]

Related

Wiki: History

Discussion

  • Anonymous

    Anonymous - 2012-02-09

    Originally posted by: tch...@hotmail.com

    (No comment was entered for this change.)

    Status: Accepted

     
  • Anonymous

    Anonymous - 2012-02-09

    Originally posted by: tch...@hotmail.com

    Correction committed on SVN, can you test with the version from the trunk ?

    Thanks a lot.

    Status: Fixed

     
  • Anonymous

    Anonymous - 2012-02-09

    Originally posted by: Daniel...@gmail.com

    [r101]

    current output is:
    $ php run.php --src test.php --format console
    test.php WARNING Line:4 - function 'unusedCodeProblem1' has unused code after RETURN.
    test.php WARNING Line:8 - The statement 'if' must contain its code within a {} block.
    test.php WARNING Line:8 - function 'unusedCodeProblem2' has unused code after RETURN.

    The first part is OK, line 4 is unused.

    But is still says "Line:8 ... unnused code...", but it is not true.

     
  • Anonymous

    Anonymous - 2012-02-10

    Originally posted by: tch...@hotmail.com

    (No comment was entered for this change.)

    Status: Accepted

     
  • Anonymous

    Anonymous - 2012-02-10

    Originally posted by: tch...@hotmail.com

    OK, this is more complicated than I tought. The problem is I don't dectect correctly the statement after IF because there is no curly opening.

    I should improve the detection of the statement for all control statements. The line between the control statement and the next ";" should be considered as the statement.
    But the conditional part should be ignored which is difficult. I think I need to count the parenthesis openings and closing.

     
  • Anonymous

    Anonymous - 2012-02-13

    Originally posted by: tch...@hotmail.com

    OK, new try.

    Returns and Throws are taking into account only when they are at level 0 of a function. When they are in a statement they are ignored.

    Can you retry ?

    Thanks,

    Status: Fixed

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.