Skip to content
Merged
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
74 changes: 51 additions & 23 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,18 @@ public function append(array $data, $id = null, bool $append = true, $linesToBeC
}
}

foreach ($fileData['functions'] as $function => $functionCoverage) {
foreach ($functionCoverage['branches'] as $branch => $branchCoverage) {
if (($branchCoverage['hit'] ?? 0) === 1) {
$this->addCoverageBranchHit($file, $function, $branch, $branchCoverage['hit'] ?? 0);
$this->addCoverageBranchTest($file, $function, $branch, $id);
if ($this->determineBranchCoverage) {
foreach ($fileData['functions'] as $function => $functionCoverage) {
foreach ($functionCoverage['branches'] as $branch => $branchCoverage) {
if (($branchCoverage['hit'] ?? 0) === 1) {
$this->addCoverageBranchHit($file, $function, $branch, $branchCoverage['hit'] ?? 0);
$this->addCoverageBranchTest($file, $function, $branch, $id);
}
}
}

foreach ($functionCoverage['paths'] as $path => $pathCoverage) {
$this->addCoveragePathHit($file, $function, $path, $pathCoverage['hit'] ?? 0);
foreach ($functionCoverage['paths'] as $path => $pathCoverage) {
$this->addCoveragePathHit($file, $function, $path, $pathCoverage['hit'] ?? 0);
}
}
}
}
Expand Down Expand Up @@ -622,20 +624,21 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
} else {
$this->addCoverageLinePathCovered($file, $lineNumber, false);
}

}

foreach ($fileData['functions'] as $functionName => $functionData) {
$this->data[$file]['paths'][$functionName] = $functionData['paths'];
if ($this->determineBranchCoverage) {
foreach ($fileData['functions'] as $functionName => $functionData) {
$this->data[$file]['paths'][$functionName] = $functionData['paths'];

foreach ($functionData['branches'] as $branchIndex => $branchData) {
$this->addCoverageBranchHit($file, $functionName, $branchIndex, $branchData['hit']);
$this->addCoverageBranchLineStart($file, $functionName, $branchIndex, $branchData['line_start']);
$this->addCoverageBranchLineEnd($file, $functionName, $branchIndex, $branchData['line_end']);
foreach ($functionData['branches'] as $branchIndex => $branchData) {
$this->addCoverageBranchHit($file, $functionName, $branchIndex, $branchData['hit']);
$this->addCoverageBranchLineStart($file, $functionName, $branchIndex, $branchData['line_start']);
$this->addCoverageBranchLineEnd($file, $functionName, $branchIndex, $branchData['line_end']);

for ($curLine = $branchData['line_start']; $curLine < $branchData['line_end']; $curLine++) {
if (isset($this->data[$file]['lines'][$curLine])) {
$this->addCoverageLinePathCovered($file, $curLine, (bool) $branchData['hit']);
for ($curLine = $branchData['line_start']; $curLine < $branchData['line_end']; $curLine++) {
if (isset($this->data[$file]['lines'][$curLine])) {
$this->addCoverageLinePathCovered($file, $curLine, (bool) $branchData['hit']);
}
}
}
}
Expand All @@ -646,11 +649,17 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data): void
private function initializeFileCoverageData(string $file): void
{
if (!isset($this->data[$file]) && $this->filter->isFile($file)) {
$this->data[$file] = [
'lines' => [],
'branches' => [],
'paths' => [],
];
$default = ['lines' => []];

if ($this->determineBranchCoverage) {
$default = [
'lines' => [],
'branches' => [],
'paths' => [],
];
}

$this->data[$file] = $default;
}
}

Expand Down Expand Up @@ -689,6 +698,9 @@ private function addCoverageLineTest(string $file, int $lineNumber, string $test
private function addCoverageBranchHit(string $file, string $functionName, int $branchIndex, int $hit): void
{
$this->initializeFileCoverageData($file);
if (!$this->determineBranchCoverage) {
return;
}

if (!\array_key_exists($functionName, $this->data[$file]['branches'])) {
$this->data[$file]['branches'][$functionName] = [];
Expand Down Expand Up @@ -717,6 +729,10 @@ private function addCoverageBranchLineStart(
): void {
$this->initializeFileCoverageData($file);

if (!$this->determineBranchCoverage) {
return;
}

if (!\array_key_exists($functionName, $this->data[$file]['branches'])) {
$this->data[$file]['branches'][$functionName] = [];
}
Expand All @@ -741,6 +757,10 @@ private function addCoverageBranchLineEnd(
): void {
$this->initializeFileCoverageData($file);

if (!$this->determineBranchCoverage) {
return;
}

if (!\array_key_exists($functionName, $this->data[$file]['branches'])) {
$this->data[$file]['branches'][$functionName] = [];
}
Expand All @@ -765,6 +785,10 @@ private function addCoverageBranchTest(
): void {
$this->initializeFileCoverageData($file);

if (!$this->determineBranchCoverage) {
return;
}

if (!\array_key_exists($functionName, $this->data[$file]['branches'])) {
$this->data[$file]['branches'][$functionName] = [];
}
Expand All @@ -791,6 +815,10 @@ private function addCoveragePathHit(
): void {
$this->initializeFileCoverageData($file);

if (!$this->determineBranchCoverage) {
return;
}

if (!\array_key_exists($functionName, $this->data[$file]['paths'])) {
$this->data[$file]['paths'][$functionName] = [];
}
Expand Down