Skip to content
This repository has been archived by the owner on Feb 27, 2020. It is now read-only.

Commented-out code still triggers errors #40

Open
zbee opened this issue Jun 27, 2018 · 3 comments
Open

Commented-out code still triggers errors #40

zbee opened this issue Jun 27, 2018 · 3 comments

Comments

@zbee
Copy link

zbee commented Jun 27, 2018

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
Copy link

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
Copy link

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
Copy link

mbomb007 commented Feb 8, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants