summaryrefslogtreecommitdiff
path: root/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php')
-rw-r--r--vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php b/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
index 422742e28..9cb20e731 100644
--- a/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
+++ b/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
@@ -15,8 +15,12 @@ use function array_flip;
use function array_intersect;
use function array_intersect_key;
use function count;
+use function explode;
+use function file_get_contents;
use function in_array;
+use function is_file;
use function range;
+use function trim;
use SebastianBergmann\CodeCoverage\Driver\Driver;
use SebastianBergmann\CodeCoverage\StaticAnalysis\FileAnalyser;
@@ -87,7 +91,7 @@ final class RawCodeCoverageData
{
$lineCoverage = [];
- foreach ($analyser->executableLinesIn($filename) as $line) {
+ foreach ($analyser->executableLinesIn($filename) as $line => $branch) {
$lineCoverage[$line] = Driver::LINE_NOT_EXECUTED;
}
@@ -138,6 +142,42 @@ final class RawCodeCoverageData
}
/**
+ * @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
*/
public function keepFunctionCoverageDataOnlyForLines(string $filename, array $lines): void