php7mar icon indicating copy to clipboard operation
php7mar copied to clipboard

Commented-out code still triggers errors

Open zbee opened this issue 7 years ago • 3 comments

I used this on a test box at work to run against our code base to show how simple upgrading to PHP 7.2 will be (from 5.6) given the improvements, but the generated report showed probably 75% of errors originating from commented out lines (I don't know why we have so many, but that's a task for another time) these should be ignored to boot. This included single line comments and block comments.

For example:

This code is clearly commented out, yet gets flagged.

It wouldn't be wrong to include this in a notices section or something of the like, just to make users aware that they have comments full of deprecated code like we do for some unknown reason; but it shouldn't show in the main list of problems.

zbee avatar Jun 27 '18 00:06 zbee

I agree. There should be an option to ignore comments, or they should be under a lesser category. A comment typo with an extra dollar sign in front of a variable should not count as Critical.

mbomb007 avatar Nov 21 '18 15:11 mbomb007

This is an easy fix. In php7mar/classes/test.php:

function testLine($line) $issues = []; $testLine = ltrim($line); if(substr($testLine,0,2) == "//" || substr($testLine,0,1) == "#") return $issues. ...

rembrandtXIII avatar Feb 08 '19 12:02 rembrandtXIII

This is an easy fix. In php7mar/classes/test.php:

function testLine($line) $issues = []; $testLine = ltrim($line); if(substr($testLine,0,2) == "//" || substr($testLine,0,1) == "#") return $issues. ...

That suggestion does not take multi-line comments into account, such as:

/**
 * Comment
 */

Nor does it handle comments that are not at the start of a line. This would still throw a critical error:

$test = $value + 1; // Add one to $$test.

mbomb007 avatar Feb 08 '19 16:02 mbomb007