Skip to content

Commit 07f22dc

Browse files
Adapt drivers to raw data format used by Xdebug when XDEBUG_CC_BRANCH_CHECK is set
1 parent 4b06905 commit 07f22dc

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

src/CodeCoverage/Data/FileCollection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ class PHP_CodeCoverage_Data_FileCollection implements Countable, IteratorAggrega
6767
*/
6868
public function processData($id, array $data)
6969
{
70-
foreach ($data as $file => $lines) {
70+
foreach ($data as $file => $_data) {
7171
if (!isset($this->files[$file])) {
72-
$this->createFile($file, $lines);
72+
$this->createFile($file, $_data);
7373
}
7474

7575
$_lines = array();
7676

77-
foreach ($lines as $lineNumber => $flag) {
77+
foreach ($_data['lines'] as $lineNumber => $flag) {
7878
if ($flag == 1) {
7979
$_lines[] = $lineNumber;
8080
}
@@ -93,15 +93,15 @@ public function merge(PHP_CodeCoverage_Data_FileCollection $other)
9393

9494
/**
9595
* @param string $path
96-
* @param array $lines
96+
* @param array $data
9797
*/
98-
private function createFile($path, array $lines)
98+
private function createFile($path, array $data)
9999
{
100100
$_lines = new PHP_CodeCoverage_Data_LineCollection;
101101
$functions = new PHP_CodeCoverage_Data_FunctionCollection;
102102
// @todo Populate $functions
103103

104-
foreach ($lines as $lineNumber => $flag) {
104+
foreach ($data['lines'] as $lineNumber => $flag) {
105105
$opcodes = new PHP_CodeCoverage_Data_OpcodeCollection;
106106
// @todo Populate $opcodes
107107

src/CodeCoverage/Driver/HHVM.php

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

8989
return $data;
9090
}
91+
92+
/**
93+
* @param array $data
94+
*/
95+
protected function cleanup(array &$data)
96+
{
97+
foreach (array_keys($data) as $file) {
98+
$data[$file] = array('lines' => $data[$file]);
99+
}
100+
}
91101
}
102+

src/CodeCoverage/Driver/Xdebug.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@
5858
class PHP_CodeCoverage_Driver_Xdebug extends PHP_CodeCoverage_Driver
5959
{
6060
/**
61-
* @throws PHP_CodeCoverage_Exception
61+
* @var integer
62+
*/
63+
private $flags = false;
64+
65+
/**
66+
* Constructor.
6267
*/
6368
protected function ensureDriverCanWork()
6469
{
@@ -72,14 +77,20 @@ protected function ensureDriverCanWork()
7277
'xdebug.coverage_enable=On has to be set in php.ini'
7378
);
7479
}
80+
81+
$this->flags = XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE;
82+
83+
if (defined('XDEBUG_CC_BRANCH_CHECK')) {
84+
$this->flags |= XDEBUG_CC_BRANCH_CHECK;
85+
}
7586
}
7687

7788
/**
7889
* Start collection of code coverage information.
7990
*/
8091
protected function doStart()
8192
{
82-
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
93+
xdebug_start_code_coverage($this->flags);
8394
}
8495

8596
/**
@@ -102,16 +113,20 @@ protected function doStop()
102113
protected function cleanup(array &$data)
103114
{
104115
foreach (array_keys($data) as $file) {
105-
if (isset($data[$file][0])) {
106-
unset($data[$file][0]);
116+
if (!isset($data[$file]['lines'])) {
117+
$data[$file] = array('lines' => $data[$file]);
118+
}
119+
120+
if (isset($data[$file]['lines'][0])) {
121+
unset($data[$file]['lines'][0]);
107122
}
108123

109124
if (file_exists($file)) {
110125
$numLines = PHP_CodeCoverage_Util::numberOfLinesInFile($file);
111126

112-
foreach (array_keys($data[$file]) as $line) {
113-
if (isset($data[$file][$line]) && $line > $numLines) {
114-
unset($data[$file][$line]);
127+
foreach (array_keys($data[$file]['lines']) as $line) {
128+
if (isset($data[$file]['lines'][$line]) && $line > $numLines) {
129+
unset($data[$file]['lines'][$line]);
115130
}
116131
}
117132
}

0 commit comments

Comments
 (0)