Skip to content

Commit

Permalink
Fix CS/WS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 14, 2022
1 parent 23555f3 commit 2016ff1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,12 @@ private function applyExecutableLinesFilter(RawCodeCoverageData $data): void
}

$linesToBranchMap = $this->analyser()->executableLinesIn($filename);

$data->keepLineCoverageDataOnlyForLines(
$filename,
array_keys($linesToBranchMap)
);

$data->markExecutableLineByBranch(
$filename,
$linesToBranchMap
Expand Down
31 changes: 17 additions & 14 deletions src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public function enterNode(Node $node): void
}

if ($node instanceof Node\Scalar\String_ ||
$node instanceof Node\Scalar\EncapsedStringPart
) {
$node instanceof Node\Scalar\EncapsedStringPart) {
$startLine = $node->getStartLine() + 1;
$endLine = $node->getEndLine() - 1;

Expand Down Expand Up @@ -108,17 +107,15 @@ public function enterNode(Node $node): void
$node instanceof Node\Identifier ||
$node instanceof Node\Name ||
$node instanceof Node\Param ||
$node instanceof Node\Scalar
) {
$node instanceof Node\Scalar) {
return;
}

if ($node instanceof Node\Stmt\Function_ ||
$node instanceof Node\Stmt\Class_ ||
$node instanceof Node\Stmt\ClassMethod ||
$node instanceof Node\Expr\Closure ||
$node instanceof Node\Stmt\Trait_
) {
$node instanceof Node\Stmt\Trait_) {
$isConcreteClassLike = $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_;

if (null !== $node->stmts) {
Expand Down Expand Up @@ -169,6 +166,7 @@ public function enterNode(Node $node): void
$node->getStartLine() + 1,
$node->expr->getStartLine()
);

$endLine = $node->expr->getEndLine();

if ($endLine < $startLine) {
Expand All @@ -182,8 +180,7 @@ public function enterNode(Node $node): void

if ($node instanceof Node\Expr\Ternary) {
if (null !== $node->if &&
$node->getStartLine() !== $node->if->getEndLine()
) {
$node->getStartLine() !== $node->if->getEndLine()) {
$this->setLineBranch($node->if->getStartLine(), $node->if->getEndLine(), ++$this->nextBranch);
}

Expand All @@ -204,8 +201,7 @@ public function enterNode(Node $node): void

if ($node instanceof Node\Stmt\If_ ||
$node instanceof Node\Stmt\ElseIf_ ||
$node instanceof Node\Stmt\Case_
) {
$node instanceof Node\Stmt\Case_) {
if (null === $node->cond) {
return;
}
Expand All @@ -225,26 +221,35 @@ public function enterNode(Node $node): void

if ([] !== $node->init) {
$startLine = $node->init[0]->getStartLine();

end($node->init);

$endLine = current($node->init)->getEndLine();

reset($node->init);
}

if ([] !== $node->cond) {
if (null === $startLine) {
$startLine = $node->cond[0]->getStartLine();
}

end($node->cond);

$endLine = current($node->cond)->getEndLine();

reset($node->cond);
}

if ([] !== $node->loop) {
if (null === $startLine) {
$startLine = $node->loop[0]->getStartLine();
}

end($node->loop);

$endLine = current($node->loop)->getEndLine();

reset($node->loop);
}

Expand Down Expand Up @@ -272,8 +277,7 @@ public function enterNode(Node $node): void
}

if ($node instanceof Node\Stmt\While_ ||
$node instanceof Node\Stmt\Do_
) {
$node instanceof Node\Stmt\Do_) {
$this->setLineBranch(
$node->cond->getStartLine(),
$node->cond->getEndLine(),
Expand Down Expand Up @@ -328,8 +332,7 @@ public function afterTraverse(array $nodes): void
(
isset($this->commentsToCheckForUnset[$lineNumber]) &&
1 === preg_match(sprintf('/^\s*%s\s*$/', preg_quote($this->commentsToCheckForUnset[$lineNumber], '/')), $line)
)
) {
)) {
unset($this->executableLinesGroupedByBranch[$lineNumber]);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/StaticAnalysis/ParsingFileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ private function findLinesIgnoredByLineBasedAnnotations(string $filename, string

foreach (token_get_all($source) as $token) {
if (!is_array($token) ||
!(T_COMMENT === $token[0] || T_DOC_COMMENT === $token[0])
) {
!(T_COMMENT === $token[0] || T_DOC_COMMENT === $token[0])) {
continue;
}

Expand Down

0 comments on commit 2016ff1

Please sign in to comment.