Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions PHP/CodeCoverage/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,24 @@ public static function getLinesToBeIgnored($filename, $cacheTokens = TRUE)
$stop = TRUE;
}

// be sure the comment doesn't have some token BEFORE it on the same line...
// it would not be safe to ignore the whole line in those cases.
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++) {
self::$ignoredLines[$filename][$i] = TRUE;
}

if ($token instanceof PHP_Token_DOC_COMMENT) {
// Workaround for the fact the DOC_COMMENT token
// does not include the final \n character in its
// text.
if (substr(trim($lines[$i-1]), -2) == '*/') {
self::$ignoredLines[$filename][$i] = TRUE;
}
// 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)) {
self::$ignoredLines[$filename][$i] = TRUE;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/PHP/CodeCoverage/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ public function testGetLinesToBeIgnoredOneLineAnnotations()
14 => TRUE,
17 => TRUE,
19 => TRUE,
20 => TRUE,
22 => TRUE,
23 => TRUE,
24 => TRUE,
26 => TRUE,
27 => TRUE,
28 => TRUE,
29 => TRUE,
Expand Down