Alexia / php7mar

PHP 7 Migration Assistant Report (MAR)
GNU General Public License v3.0
797 stars 133 forks source link

Commented-out code still triggers errors #40

Open zbee opened 6 years ago

zbee commented 6 years ago

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.

mbomb007 commented 5 years ago

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.

rembrandtXIII commented 5 years ago

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. ...

mbomb007 commented 5 years ago

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.