Skip to content

Commit 496bb0a

Browse files
GeLoLabssebastianbergmann
authored andcommitted
Ignore comment starting by '/*'
1 parent 1c29ed6 commit 496bb0a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/CodeCoverage/Parser.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*/
4545

4646
/**
47-
*
47+
*
4848
*
4949
* @category PHP
5050
* @package CodeCoverage
@@ -164,22 +164,24 @@ public function getLinesToBeIgnored($filename)
164164
$stop = true;
165165
}
166166

167-
// Do not ignore the whole line when there is a token
168-
// before the comment on the same line
169-
if (0 === strpos($_token, $_line)) {
170-
$count = substr_count($token, "\n");
171-
$line = $token->getLine();
167+
if (!$ignore) {
168+
$start = $token->getLine();
169+
$end = $start + substr_count($token, "\n");
170+
171+
// Do not ignore the first line when there is a token
172+
// before the comment
173+
if (0 !== strpos($_token, $_line)) {
174+
$start++;
175+
}
172176

173-
for ($i = $line; $i < $line + $count; $i++) {
177+
for ($i = $start; $i < $end; $i++) {
174178
$this->ignoredLines[$filename][] = $i;
175179
}
176180

177-
if ($token instanceof PHP_Token_DOC_COMMENT) {
178-
// The DOC_COMMENT token does not contain the
179-
// final \n character in its text
180-
if (substr(trim($lines[$i-1]), -2) == '*/') {
181-
$this->ignoredLines[$filename][] = $i;
182-
}
181+
// A DOC_COMMENT token or a COMMENT token starting with "/*"
182+
// does not contain the final \n character in its text
183+
if (0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i-1]), -2)) {
184+
$this->ignoredLines[$filename][] = $i;
183185
}
184186
}
185187
break;

tests/PHP/CodeCoverage/ParserTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ public function ignoredLinesProvider()
108108
16,
109109
18,
110110
20,
111+
21,
111112
23,
112113
24,
114+
25,
115+
27,
113116
28,
114117
29,
115118
30,

0 commit comments

Comments
 (0)