diff options
Diffstat (limited to 'vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php')
-rw-r--r-- | vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php | 68 |
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]) + ); } } } |