Skip to content

Commit 2c00856

Browse files
author
imsamurai
committed
code coverage driver hhvm fix
1 parent a995604 commit 2c00856

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/CodeCoverage/Driver/HHVM.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,52 @@ protected function doStop()
8888

8989
return $data;
9090
}
91+
92+
/**
93+
* {@inheritdoc}
94+
*
95+
* @param array $data
96+
*/
97+
protected function cleanup(array &$data)
98+
{
99+
foreach (array_keys($data) as $file) {
100+
if (!file_exists($file)) {
101+
continue;
102+
}
103+
104+
$lines = $this->getLines($file);
105+
foreach ($lines as $line => $dead) {
106+
if ($dead) {
107+
$data[$file][$line] = -2;
108+
} elseif (isset($data[$file][$line])) {
109+
$data[$file][$line] = 1;
110+
} else {
111+
$data[$file][$line] = -1;
112+
}
113+
}
114+
}
115+
return $data;
116+
}
117+
118+
/**
119+
* Returns file lines anad mark some as dead
120+
*
121+
* @param string $file
122+
* @return array
123+
*/
124+
private function getLines($file)
125+
{
126+
$buffer = file($file);
127+
$lines = array();
128+
129+
foreach ($buffer as $line => $content) {
130+
if (trim($content) === '}') {
131+
$lines[$line + 1] = true;
132+
continue;
133+
}
134+
$lines[$line + 1] = false;
135+
}
136+
return $lines;
137+
}
138+
91139
}

0 commit comments

Comments
 (0)