summaryrefslogtreecommitdiff
path: root/vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-12-02 17:45:25 +0300
committerAndrew Dolgov <[email protected]>2023-12-02 18:03:06 +0300
commit09898ccbc87b5e297bcfab4527a3705bd3b4d5a4 (patch)
treeebb1e6ebe21782f4c1a757a00af1316ca645b69e /vendor/phpunit/php-code-coverage/src/RawCodeCoverageData.php
parent2b8e34453234b8b31ebc9e7020f8677bf3889898 (diff)
add phpunit code coverage driver
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