Skip to content

Commit 121d8c7

Browse files
Work around Xdebug issue where lines that do not exist are marked as being executed
1 parent 3a39650 commit 121d8c7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/CodeCoverage/Driver/Xdebug.php

+27
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,35 @@ private function cleanup(array $data)
106106
if (isset($data[$file][0])) {
107107
unset($data[$file][0]);
108108
}
109+
110+
if (file_exists($file)) {
111+
$numLines = $this->getNumberOfLinesInFile($file);
112+
113+
foreach (array_keys($data[$file]) as $line) {
114+
if (isset($data[$file][$line]) && $line > $numLines) {
115+
unset($data[$file][$line]);
116+
}
117+
}
118+
}
109119
}
110120

111121
return $data;
112122
}
123+
124+
/**
125+
* @param string $file
126+
* @return integer
127+
* @since Method available since Release 2.0.0
128+
*/
129+
private function getNumberOfLinesInFile($file)
130+
{
131+
$buffer = file_get_contents($file);
132+
$lines = substr_count($buffer, "\n");
133+
134+
if (substr($buffer, -1) !== "\n") {
135+
$lines++;
136+
}
137+
138+
return $lines;
139+
}
113140
}

0 commit comments

Comments
 (0)