Skip to content

Commit 0a19874

Browse files
Slamdunksebastianbergmann
authored andcommitted
Simplified matching of node to be skipped
1 parent 3b9a480 commit 0a19874

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
3131
*/
3232
private $executableLinesGroupedByBranch = [];
3333

34-
/**
35-
* @var array
36-
*/
37-
private $unsets = [];
38-
3934
public function enterNode(Node $node): void
4035
{
41-
if ($node instanceof Node\Stmt\Class_) {
36+
if ($node instanceof Node\Stmt\Declare_ ||
37+
$node instanceof Node\Stmt\DeclareDeclare ||
38+
$node instanceof Node\Stmt\Class_ ||
39+
$node instanceof Node\Stmt\ClassConst ||
40+
$node instanceof Node\Stmt\Property ||
41+
$node instanceof Node\Stmt\PropertyProperty ||
42+
$node instanceof Node\Const_ ||
43+
$node instanceof Node\Scalar ||
44+
$node instanceof Node\Identifier ||
45+
$node instanceof Node\VarLikeIdentifier
46+
) {
4247
return;
4348
}
4449

@@ -240,32 +245,13 @@ public function enterNode(Node $node): void
240245
return;
241246
}
242247

243-
if ($node instanceof Node\Stmt\Declare_) {
244-
$this->unsets[] = range($node->getStartLine(), $node->getEndLine());
245-
246-
return;
247-
}
248-
249-
if ($node instanceof Node\Identifier) {
250-
return;
251-
}
252-
253248
if (isset($this->executableLinesGroupedByBranch[$node->getStartLine()])) {
254249
return;
255250
}
256251

257252
$this->setLineBranch($node->getStartLine(), $node->getEndLine(), 1);
258253
}
259254

260-
public function afterTraverse(array $nodes): void
261-
{
262-
foreach ($this->unsets as $unset) {
263-
foreach ($unset as $line) {
264-
unset($this->executableLinesGroupedByBranch[$line]);
265-
}
266-
}
267-
}
268-
269255
public function executableLinesGroupedByBranch(): array
270256
{
271257
return $this->executableLinesGroupedByBranch;

tests/_files/source_for_branched_exec_lines.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function withIf() // +6
4444

4545
class MyClass
4646
{
47+
public const C1 = 1;
48+
public $var1 = 1;
4749
public // +2
4850
function // 0
4951
__construct // 0

0 commit comments

Comments
 (0)