class IgnoredLinesFindingVisitor
@internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
Hierarchy
- class \PhpParser\NodeVisitorAbstract implements \PhpParser\NodeVisitor
- class \SebastianBergmann\CodeCoverage\StaticAnalysis\IgnoredLinesFindingVisitor extends \PhpParser\NodeVisitorAbstract
Expanded class hierarchy of IgnoredLinesFindingVisitor
File
-
vendor/
phpunit/ php-code-coverage/ src/ StaticAnalysis/ IgnoredLinesFindingVisitor.php, line 27
Namespace
SebastianBergmann\CodeCoverage\StaticAnalysisView source
final class IgnoredLinesFindingVisitor extends NodeVisitorAbstract {
/**
* @psalm-var array<int>
*/
private array $ignoredLines = [];
private readonly bool $useAnnotationsForIgnoringCode;
private readonly bool $ignoreDeprecated;
public function __construct(bool $useAnnotationsForIgnoringCode, bool $ignoreDeprecated) {
$this->useAnnotationsForIgnoringCode = $useAnnotationsForIgnoringCode;
$this->ignoreDeprecated = $ignoreDeprecated;
}
public function enterNode(Node $node) : void {
if (!$node instanceof Class_ && !$node instanceof Trait_ && !$node instanceof Interface_ && !$node instanceof Enum_ && !$node instanceof ClassMethod && !$node instanceof Function_ && !$node instanceof Attribute) {
return;
}
if ($node instanceof Class_ && $node->isAnonymous()) {
return;
}
if ($node instanceof Class_ || $node instanceof Trait_ || $node instanceof Interface_ || $node instanceof Attribute) {
$this->ignoredLines[] = $node->getStartLine();
assert($node->name !== null);
// Workaround for https://github.com/nikic/PHP-Parser/issues/886
$this->ignoredLines[] = $node->name
->getStartLine();
}
if (!$this->useAnnotationsForIgnoringCode) {
return;
}
if ($node instanceof Interface_) {
return;
}
if ($node instanceof Attribute && $node->name
->toString() === 'PHPUnit\\Framework\\Attributes\\CodeCoverageIgnore') {
$attributeGroup = $node->getAttribute('parent');
$attributedNode = $attributeGroup->getAttribute('parent');
for ($line = $attributedNode->getStartLine(); $line <= $attributedNode->getEndLine(); $line++) {
$this->ignoredLines[] = $line;
}
return;
}
$this->processDocComment($node);
}
/**
* @psalm-return array<int>
*/
public function ignoredLines() : array {
return $this->ignoredLines;
}
private function processDocComment(Node $node) : void {
$docComment = $node->getDocComment();
if ($docComment === null) {
return;
}
if (str_contains($docComment->getText(), '@codeCoverageIgnore')) {
for ($line = $node->getStartLine(); $line <= $node->getEndLine(); $line++) {
$this->ignoredLines[] = $line;
}
}
if ($this->ignoreDeprecated && str_contains($docComment->getText(), '@deprecated')) {
for ($line = $node->getStartLine(); $line <= $node->getEndLine(); $line++) {
$this->ignoredLines[] = $line;
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
IgnoredLinesFindingVisitor::$ignoreDeprecated | private | property | |||
IgnoredLinesFindingVisitor::$ignoredLines | private | property | @psalm-var array<int> | ||
IgnoredLinesFindingVisitor::$useAnnotationsForIgnoringCode | private | property | |||
IgnoredLinesFindingVisitor::enterNode | public | function | Called when entering a node. | Overrides NodeVisitorAbstract::enterNode | |
IgnoredLinesFindingVisitor::ignoredLines | public | function | @psalm-return array<int> | ||
IgnoredLinesFindingVisitor::processDocComment | private | function | |||
IgnoredLinesFindingVisitor::__construct | public | function | |||
NodeVisitor::DONT_TRAVERSE_CHILDREN | public | constant | If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes of the current node will not be traversed for any visitors. |
||
NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN | public | constant | If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes of the current node will not be traversed for any visitors. |
||
NodeVisitor::REMOVE_NODE | public | constant | If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs in an array, it will be removed from the array. |
||
NodeVisitor::REPLACE_WITH_NULL | public | constant | If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns REPLACE_WITH_NULL, the node will be replaced with null. This is not a legal return value if the node is part of an array, rather than another node. |
||
NodeVisitor::STOP_TRAVERSAL | public | constant | If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns STOP_TRAVERSAL, traversal is aborted. |
||
NodeVisitorAbstract::afterTraverse | public | function | Called once after traversal. | Overrides NodeVisitor::afterTraverse | 1 |
NodeVisitorAbstract::beforeTraverse | public | function | Called once before traversal. | Overrides NodeVisitor::beforeTraverse | 5 |
NodeVisitorAbstract::leaveNode | public | function | Called when leaving a node. | Overrides NodeVisitor::leaveNode | 2 |