From b101ba4585a2436585fe410f4ffdaa7cfbbe180b Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Fri, 27 Jun 2014 20:19:54 +0200 Subject: [PATCH] Ignore comment starting by '/*' --- src/CodeCoverage.php | 26 ++++++++++++++------------ tests/PHP/CodeCoverageTest.php | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 1debd145b..06161e299 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -714,22 +714,24 @@ private function getLinesToBeIgnored($filename) $stop = true; } - // Do not ignore the whole line when there is a token - // before the comment on the same line - if (0 === strpos($_token, $_line)) { - $count = substr_count($token, "\n"); - $line = $token->getLine(); + if (!$ignore) { + $start = $token->getLine(); + $end = $start + substr_count($token, "\n"); + + // Do not ignore the first line when there is a token + // before the comment + if (0 !== strpos($_token, $_line)) { + $start++; + } - for ($i = $line; $i < $line + $count; $i++) { + for ($i = $start; $i < $end; $i++) { $this->ignoredLines[$filename][] = $i; } - if ($token instanceof PHP_Token_DOC_COMMENT) { - // The DOC_COMMENT token does not contain the - // final \n character in its text - if (substr(trim($lines[$i-1]), -2) == '*/') { - $this->ignoredLines[$filename][] = $i; - } + // A DOC_COMMENT token or a COMMENT token starting with "/*" + // does not contain the final \n character in its text + if (0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i-1]), -2)) { + $this->ignoredLines[$filename][] = $i; } } break; diff --git a/tests/PHP/CodeCoverageTest.php b/tests/PHP/CodeCoverageTest.php index 745657c1f..e167b1a8f 100644 --- a/tests/PHP/CodeCoverageTest.php +++ b/tests/PHP/CodeCoverageTest.php @@ -448,8 +448,11 @@ public function testGetLinesToBeIgnoredOneLineAnnotations() 16, 18, 20, + 21, 23, 24, + 25, + 27, 28, 29, 30,