summaryrefslogtreecommitdiff
path: root/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.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/StaticAnalysis/ParsingFileAnalyser.php
parent2b8e34453234b8b31ebc9e7020f8677bf3889898 (diff)
add phpunit code coverage driver
Diffstat (limited to 'vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php')
-rw-r--r--vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php68
1 files changed, 35 insertions, 33 deletions
diff --git a/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php b/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php
index 8edf973e2..e68638219 100644
--- a/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php
+++ b/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php
@@ -9,11 +9,14 @@
*/
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
+use function array_merge;
use function array_unique;
use function assert;
use function file_get_contents;
use function is_array;
use function max;
+use function range;
+use function sort;
use function sprintf;
use function substr_count;
use function token_get_all;
@@ -153,7 +156,7 @@ final class ParsingFileAnalyser implements FileAnalyser
$codeUnitFindingVisitor = new CodeUnitFindingVisitor;
$lineCountingVisitor = new LineCountingVisitor($linesOfCode);
$ignoredLinesFindingVisitor = new IgnoredLinesFindingVisitor($this->useAnnotationsForIgnoringCode, $this->ignoreDeprecatedCode);
- $executableLinesFindingVisitor = new ExecutableLinesFindingVisitor;
+ $executableLinesFindingVisitor = new ExecutableLinesFindingVisitor($source);
$traverser->addVisitor(new NameResolver);
$traverser->addVisitor(new ParentConnectingVisitor);
@@ -172,7 +175,7 @@ final class ParsingFileAnalyser implements FileAnalyser
$filename,
$error->getMessage()
),
- (int) $error->getCode(),
+ $error->getCode(),
$error
);
}
@@ -181,7 +184,7 @@ final class ParsingFileAnalyser implements FileAnalyser
$this->classes[$filename] = $codeUnitFindingVisitor->classes();
$this->traits[$filename] = $codeUnitFindingVisitor->traits();
$this->functions[$filename] = $codeUnitFindingVisitor->functions();
- $this->executableLines[$filename] = $executableLinesFindingVisitor->executableLines();
+ $this->executableLines[$filename] = $executableLinesFindingVisitor->executableLinesGroupedByBranch();
$this->ignoredLines[$filename] = [];
$this->findLinesIgnoredByLineBasedAnnotations($filename, $source, $this->useAnnotationsForIgnoringCode);
@@ -206,45 +209,44 @@ final class ParsingFileAnalyser implements FileAnalyser
private function findLinesIgnoredByLineBasedAnnotations(string $filename, string $source, bool $useAnnotationsForIgnoringCode): void
{
- $ignore = false;
- $stop = false;
+ if (!$useAnnotationsForIgnoringCode) {
+ return;
+ }
+
+ $start = false;
foreach (token_get_all($source) as $token) {
- if (!is_array($token)) {
+ if (!is_array($token) ||
+ !(T_COMMENT === $token[0] || T_DOC_COMMENT === $token[0])) {
continue;
}
- switch ($token[0]) {
- case T_COMMENT:
- case T_DOC_COMMENT:
- if (!$useAnnotationsForIgnoringCode) {
- break;
- }
-
- $comment = trim($token[1]);
-
- if ($comment === '// @codeCoverageIgnore' ||
- $comment === '//@codeCoverageIgnore') {
- $ignore = true;
- $stop = true;
- } elseif ($comment === '// @codeCoverageIgnoreStart' ||
- $comment === '//@codeCoverageIgnoreStart') {
- $ignore = true;
- } elseif ($comment === '// @codeCoverageIgnoreEnd' ||
- $comment === '//@codeCoverageIgnoreEnd') {
- $stop = true;
- }
-
- break;
- }
+ $comment = trim($token[1]);
- if ($ignore) {
+ if ($comment === '// @codeCoverageIgnore' ||
+ $comment === '//@codeCoverageIgnore') {
$this->ignoredLines[$filename][] = $token[2];
- if ($stop) {
- $ignore = false;
- $stop = false;
+ continue;
+ }
+
+ if ($comment === '// @codeCoverageIgnoreStart' ||
+ $comment === '//@codeCoverageIgnoreStart') {
+ $start = $token[2];
+
+ continue;
+ }
+
+ if ($comment === '// @codeCoverageIgnoreEnd' ||
+ $comment === '//@codeCoverageIgnoreEnd') {
+ if (false === $start) {
+ $start = $token[2];
}
+
+ $this->ignoredLines[$filename] = array_merge(
+ $this->ignoredLines[$filename],
+ range($start, $token[2])
+ );
}
}
}