Skip to content

Group line code-coverage by branch #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0c33d75
Move to branch based line analysis
Slamdunk Nov 21, 2022
9c508c3
Corrected `elseif`s conditions
Slamdunk Nov 24, 2022
df986ed
Added `for` and `do-while`
Slamdunk Nov 24, 2022
aff7caf
Added `switch`
Slamdunk Nov 24, 2022
7afb5e6
Added `match`
Slamdunk Nov 24, 2022
ee5db56
Added `return`
Slamdunk Nov 24, 2022
c797803
Added `continue` and `break`
Slamdunk Nov 24, 2022
74f9b32
Added `goto`
Slamdunk Nov 24, 2022
cfdfd5f
Added `try-catch-finally`
Slamdunk Nov 25, 2022
d3d30da
Added `ternary`
Slamdunk Nov 25, 2022
270211a
Added `call-like`
Slamdunk Nov 25, 2022
3337628
Handled empty functions
Slamdunk Nov 28, 2022
e03acf2
Added anonymous functions
Slamdunk Nov 28, 2022
e8af3e1
Added arrow functions
Slamdunk Nov 28, 2022
a6cef72
If condition to return statement
Slamdunk Nov 28, 2022
358256f
Simplified matching of node to be skipped
Slamdunk Nov 28, 2022
fb6e6c2
Functions/Methods: mark as lines only body's ones
Slamdunk Nov 28, 2022
7606d7c
Handle comments and empty lines
Slamdunk Nov 29, 2022
cd4f39d
CodeCoverage: mark as executed all lines of the same branch
Slamdunk Nov 29, 2022
80697da
Added `interface` and `trait`
Slamdunk Nov 29, 2022
57dfea6
Added short ternary and coalesce
Slamdunk Nov 29, 2022
489c8ae
Exclude in-toto non ClassMethods lines from class analysis
Slamdunk Nov 29, 2022
7d6b533
Assign each Stmt a separate branch
Slamdunk Nov 29, 2022
c113904
`match` arms depent too much on autoloading runtime behavior, process…
Slamdunk Nov 30, 2022
5c199ae
Lines ignored by annotations: cover entire range
Slamdunk Nov 30, 2022
8fccb72
Rely only on ExecutableLinesFindingVisitorTest unit test for exec lin…
Slamdunk Nov 30, 2022
ab90d33
Tests different features only for related supported by PHP versions
Slamdunk Nov 30, 2022
9e61b30
SA fixes
Slamdunk Nov 30, 2022
d036036
Adapt missing test cases for PHP <8.1
Slamdunk Nov 30, 2022
5243a2a
Minor optimization
Slamdunk Dec 1, 2022
1eb363a
Multiline strings: skip internal lines
Slamdunk Dec 2, 2022
d909a64
Skip comments within nodes already marked as exec
Slamdunk Dec 2, 2022
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
7 changes: 6 additions & 1 deletion src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,14 @@ private function applyExecutableLinesFilter(RawCodeCoverageData $data): void
continue;
}

$linesToBranchMap = $this->analyser()->executableLinesIn($filename);
$data->keepLineCoverageDataOnlyForLines(
$filename,
$this->analyser()->executableLinesIn($filename)
array_keys($linesToBranchMap)
);
$data->markExecutableLineByBranch(
$filename,
$linesToBranchMap
);
}
}
Expand Down
38 changes: 37 additions & 1 deletion src/RawCodeCoverageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function fromUncoveredFile(string $filename, FileAnalyser $analyse
{
$lineCoverage = [];

foreach ($analyser->executableLinesIn($filename) as $line) {
foreach ($analyser->executableLinesIn($filename) as $line => $branch) {
$lineCoverage[$line] = Driver::LINE_NOT_EXECUTED;
}

Expand Down Expand Up @@ -141,6 +141,42 @@ public function keepLineCoverageDataOnlyForLines(string $filename, array $lines)
);
}

/**
* @param int[] $linesToBranchMap
*/
public function markExecutableLineByBranch(string $filename, array $linesToBranchMap): void
{
if (!isset($this->lineCoverage[$filename])) {
return;
}

$linesByBranch = [];

foreach ($linesToBranchMap as $line => $branch) {
$linesByBranch[$branch][] = $line;
}

foreach ($this->lineCoverage[$filename] as $line => $lineStatus) {
if (!isset($linesToBranchMap[$line])) {
continue;
}

$branch = $linesToBranchMap[$line];

if (!isset($linesByBranch[$branch])) {
continue;
}

foreach ($linesByBranch[$branch] as $lineInBranch) {
$this->lineCoverage[$filename][$lineInBranch] = $lineStatus;
}

if (Driver::LINE_EXECUTED === $lineStatus) {
unset($linesByBranch[$branch]);
}
}
}

/**
* @param int[] $lines
*/
Expand Down
Loading