Skip to content

Commit

Permalink
Remove rebase errors and simplify node ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
BackEndTea committed Apr 20, 2019
1 parent 3bae203 commit 9693953
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/Visitor/MutationsCollectorVisitor.php
Expand Up @@ -109,36 +109,23 @@ public function leaveNode(Node $node): void
continue;
}

if ($isOnFunctionSignature
&& $methodNode = $node->getAttribute(ReflectionVisitor::FUNCTION_SCOPE_KEY)
) {
/** @var Node\Stmt\ClassMethod|Node\Expr\Closure $methodNode */
if ($methodNode instanceof Node\Stmt\ClassMethod && $methodNode->isAbstract()) {
continue;
}

if ($methodNode instanceof Node\Stmt\ClassMethod && $methodNode->getAttribute(ParentConnectorVisitor::PARENT_KEY) instanceof Node\Stmt\Interface_) {
continue;
}
}

if ($isOnFunctionSignature) {
// hasExecutedMethodOnLine checks for all lines of a given method,
// therefore it isn't making any sense to check any other line but first
$isCoveredByTest = $this->codeCoverageData->hasExecutedMethodOnLine($this->filePath, $node->getLine());
$linerange = range($node->getStartLine(), $node->getEndLine());
$linerange = $this->getNodeRange($node);
} else {
$outerMostArrayNode = $this->getOuterMostArrayNode($node);
$isCoveredByTest = false;
$linerange = $this->getNodeRange($outerMostArrayNode);

for ($line = $outerMostArrayNode->getStartLine(); $line <= $outerMostArrayNode->getEndLine(); ++$line) {
foreach ($linerange as $line) {
if ($this->codeCoverageData->hasTestsOnLine($this->filePath, $line)) {
$isCoveredByTest = true;

break;
}
}
$linerange = range($outerMostArrayNode->getStartLine(), $outerMostArrayNode->getEndLine());
}

if ($this->onlyCovered && !$isCoveredByTest) {
Expand Down Expand Up @@ -190,4 +177,12 @@ private function getOuterMostArrayNode(Node $node): Node

return $outerMostArrayParent;
}

/**
* @return array|int[]
*/
private function getNodeRange(Node $node): array
{
return range($node->getStartLine(), $node->getEndLine());
}
}

0 comments on commit 9693953

Please sign in to comment.