Skip to content

Commit 68a3f8e

Browse files
WIP
1 parent b54ec8f commit 68a3f8e

File tree

7 files changed

+167
-115
lines changed

7 files changed

+167
-115
lines changed

src/CodeCoverage.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
363363

364364
$this->tests[$id] = ['size' => $size, 'status' => $status];
365365

366-
foreach ($data as $file => $lines) {
366+
foreach ($data as $file => $fileCoverage) {
367367
if (!$this->filter->isFile($file)) {
368368
continue;
369369
}
370370

371-
foreach ($lines as $k => $v) {
371+
foreach ($fileCoverage['lines'] as $k => $v) {
372372
if ($v == Driver::LINE_EXECUTED) {
373-
if (empty($this->data[$file][$k]) || !in_array($id, $this->data[$file][$k])) {
374-
$this->data[$file][$k][] = $id;
373+
if (empty($this->data[$file]['lines'][$k]) || !in_array($id, $this->data[$file]['lines'][$k])) {
374+
$this->data[$file]['lines'][$k][] = $id;
375375
}
376376
}
377377
}
@@ -389,22 +389,22 @@ public function merge(CodeCoverage $that)
389389
array_merge($this->filter->getWhitelistedFiles(), $that->filter()->getWhitelistedFiles())
390390
);
391391

392-
foreach ($that->data as $file => $lines) {
392+
foreach ($that->data as $file => $fileCoverage) {
393393
if (!isset($this->data[$file])) {
394394
if (!$this->filter->isFiltered($file)) {
395-
$this->data[$file] = $lines;
395+
$this->data[$file] = $fileCoverage;
396396
}
397397

398398
continue;
399399
}
400400

401-
foreach ($lines as $line => $data) {
401+
foreach ($fileCoverage['lines'] as $line => $data) {
402402
if ($data !== null) {
403-
if (!isset($this->data[$file][$line])) {
404-
$this->data[$file][$line] = $data;
403+
if (!isset($this->data[$file]['lines'][$line])) {
404+
$this->data[$file]['lines'][$line] = $data;
405405
} else {
406-
$this->data[$file][$line] = array_unique(
407-
array_merge($this->data[$file][$line], $data)
406+
$this->data[$file]['lines'][$line] = array_unique(
407+
array_merge($this->data[$file]['lines'][$line], $data)
408408
);
409409
}
410410
}
@@ -640,8 +640,8 @@ private function applyCoversAnnotationFilter(array &$data, $linesToBeCovered, ar
640640
foreach (array_keys($data) as $filename) {
641641
$_linesToBeCovered = array_flip($linesToBeCovered[$filename]);
642642

643-
$data[$filename] = array_intersect_key(
644-
$data[$filename],
643+
$data[$filename]['lines'] = array_intersect_key(
644+
$data[$filename]['lines'],
645645
$_linesToBeCovered
646646
);
647647
}
@@ -674,7 +674,7 @@ private function applyIgnoredLinesFilter(array &$data)
674674
}
675675

676676
foreach ($this->getLinesToBeIgnored($filename) as $line) {
677-
unset($data[$filename][$line]);
677+
unset($data[$filename]['lines'][$line]);
678678
}
679679
}
680680
}
@@ -684,12 +684,12 @@ private function applyIgnoredLinesFilter(array &$data)
684684
*/
685685
private function initializeFilesThatAreSeenTheFirstTime(array $data)
686686
{
687-
foreach ($data as $file => $lines) {
687+
foreach ($data as $file => $fileCoverage) {
688688
if ($this->filter->isFile($file) && !isset($this->data[$file])) {
689-
$this->data[$file] = [];
689+
$this->data[$file] = ['lines' => [], 'functions' => $fileCoverage['functions']];
690690

691-
foreach ($lines as $k => $v) {
692-
$this->data[$file][$k] = $v == -2 ? null : [];
691+
foreach ($fileCoverage['lines'] as $k => $v) {
692+
$this->data[$file]['lines'][$k] = $v == -2 ? null : [];
693693
}
694694
}
695695
}
@@ -922,7 +922,7 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
922922
$unintentionallyCoveredUnits = [];
923923

924924
foreach ($data as $file => $_data) {
925-
foreach ($_data as $line => $flag) {
925+
foreach ($_data['lines'] as $line => $flag) {
926926
if ($flag == 1 && !isset($allowedLines[$file][$line])) {
927927
$unintentionallyCoveredUnits[] = $this->wizard->lookup($file, $line);
928928
}
@@ -953,7 +953,7 @@ private function performUnexecutedCoveredCodeCheck(array &$data, array $linesToB
953953
);
954954

955955
foreach ($data as $file => $_data) {
956-
foreach (array_keys($_data) as $line) {
956+
foreach (array_keys($_data['lines']) as $line) {
957957
if (!isset($expectedLines[$file][$line])) {
958958
continue;
959959
}
@@ -1101,9 +1101,9 @@ protected function initializeData()
11011101
continue;
11021102
}
11031103

1104-
foreach (array_keys($fileCoverage) as $key) {
1105-
if ($fileCoverage[$key] == Driver::LINE_EXECUTED) {
1106-
$fileCoverage[$key] = Driver::LINE_NOT_EXECUTED;
1104+
foreach (array_keys($fileCoverage['lines']) as $line) {
1105+
if ($fileCoverage['lines'][$line] == Driver::LINE_EXECUTED) {
1106+
$fileCoverage['lines'][$line] = Driver::LINE_NOT_EXECUTED;
11071107
}
11081108
}
11091109

src/Driver/Xdebug.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,39 @@ public function stop()
9494
private function cleanup(array $data)
9595
{
9696
foreach (array_keys($data) as $file) {
97-
unset($data[$file][0]);
97+
if (!$this->branchCoverage) {
98+
$data[$file]['lines'] = [];
99+
$data[$file]['functions'] = [];
100+
101+
foreach (array_keys($data[$file]) as $line) {
102+
if (!is_int($line)) {
103+
continue;
104+
}
105+
106+
$data[$file]['lines'][$line] = $data[$file][$line];
107+
108+
unset($data[$file][$line]);
109+
}
110+
}
111+
112+
unset($data[$file]['lines'][0]);
98113

99114
if (strpos($file, 'xdebug://debug-eval') !== 0 && file_exists($file)) {
100115
$numLines = $this->getNumberOfLinesInFile($file);
101116

102-
foreach (array_keys($data[$file]) as $line) {
117+
if (!isset($data[$file]['lines'])) {
118+
// TODO: Figure out why how this can happen
119+
$data[$file]['lines'] = [];
120+
}
121+
122+
if (!isset($data[$file]['functions'])) {
123+
// TODO: Figure out why how this can happen
124+
$data[$file]['functions'] = [];
125+
}
126+
127+
foreach (array_keys($data[$file]['lines']) as $line) {
103128
if ($line > $numLines) {
104-
unset($data[$file][$line]);
129+
unset($data[$file]['lines'][$line]);
105130
}
106131
}
107132
}

src/Node/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ protected function calculateStatistics()
431431
}
432432
}
433433

434-
if (isset($this->coverageData[$lineNumber])) {
434+
if (isset($this->coverageData['lines'][$lineNumber])) {
435435
if (isset($currentClass)) {
436436
$currentClass['executableLines']++;
437437
}
@@ -450,7 +450,7 @@ protected function calculateStatistics()
450450

451451
$this->numExecutableLines++;
452452

453-
if (count($this->coverageData[$lineNumber]) > 0) {
453+
if (count($this->coverageData['lines'][$lineNumber]) > 0) {
454454
if (isset($currentClass)) {
455455
$currentClass['executedLines']++;
456456
}

src/Report/Clover.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
5858
$xmlFile->setAttribute('name', $item->getPath());
5959

6060
$classes = $item->getClassesAndTraits();
61-
$coverage = $item->getCoverageData();
61+
$coverage = $item->getCoverageData()['lines'];
6262
$lines = [];
6363
$namespace = 'global';
6464

src/Report/Html/Renderer/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected function renderFunctionOrMethodItem(\Text_Template $template, array $i
292292
*/
293293
protected function renderSource(FileNode $node)
294294
{
295-
$coverageData = $node->getCoverageData();
295+
$coverageData = $node->getCoverageData()['lines'];
296296
$testData = $node->getTestData();
297297
$codeLines = $this->loadFile($node->getPath());
298298
$lines = '';

src/Report/Xml/Facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function processFile(FileNode $file, Directory $context)
126126
$this->processFunction($function, $fileReport);
127127
}
128128

129-
foreach ($file->getCoverageData() as $line => $tests) {
129+
foreach ($file->getCoverageData()['lines'] as $line => $tests) {
130130
if (!is_array($tests) || count($tests) == 0) {
131131
continue;
132132
}

0 commit comments

Comments
 (0)