Skip to content

Commit 9d64c5b

Browse files
starts splitting FileVisitor::enterNode in smaller methods
1 parent d34dd6d commit 9d64c5b

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/Analyzer/FileVisitor.php

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,35 @@ public function setFilePath(?string $filePath): void
2626
$this->classDescriptionBuilder->setFilePath($filePath);
2727
}
2828

29-
public function enterNode(Node $node): void
29+
public function parseClassNode(Node $node): void
3030
{
31-
if ($node instanceof Node\Stmt\Class_) {
32-
if (!$node->isAnonymous() && null !== $node->namespacedName) {
33-
$this->classDescriptionBuilder->setClassName($node->namespacedName->toCodeString());
34-
}
31+
if (!($node instanceof Node\Stmt\Class_)) {
32+
return;
33+
}
3534

36-
foreach ($node->implements as $interface) {
37-
$this->classDescriptionBuilder
38-
->addInterface($interface->toString(), $interface->getLine());
39-
}
35+
if (!$node->isAnonymous() && null !== $node->namespacedName) {
36+
$this->classDescriptionBuilder->setClassName($node->namespacedName->toCodeString());
37+
}
4038

41-
if (!$node->isAnonymous() && null !== $node->extends) {
42-
$this->classDescriptionBuilder
43-
->addExtends($node->extends->toString(), $node->getLine());
44-
}
39+
foreach ($node->implements as $interface) {
40+
$this->classDescriptionBuilder
41+
->addInterface($interface->toString(), $interface->getLine());
42+
}
4543

46-
if ($node->isFinal()) {
47-
$this->classDescriptionBuilder->setFinal(true);
48-
}
44+
if (!$node->isAnonymous() && null !== $node->extends) {
45+
$this->classDescriptionBuilder
46+
->addExtends($node->extends->toString(), $node->getLine());
47+
}
4948

50-
if ($node->isReadonly()) {
51-
$this->classDescriptionBuilder->setReadonly(true);
52-
}
49+
$this->classDescriptionBuilder->setFinal($node->isFinal());
5350

54-
if ($node->isAbstract()) {
55-
$this->classDescriptionBuilder->setAbstract(true);
56-
}
57-
}
51+
$this->classDescriptionBuilder->setReadonly($node->isReadonly());
52+
53+
$this->classDescriptionBuilder->setAbstract($node->isAbstract());
54+
}
5855

56+
public function parseEnumNode(Node $node): void
57+
{
5958
if ($node instanceof Node\Stmt\Enum_ && null !== $node->namespacedName) {
6059
$this->classDescriptionBuilder->setClassName($node->namespacedName->toCodeString());
6160
$this->classDescriptionBuilder->setEnum(true);
@@ -65,7 +64,10 @@ public function enterNode(Node $node): void
6564
->addInterface($interface->toString(), $interface->getLine());
6665
}
6766
}
67+
}
6868

69+
public function parseStaticClassConstantNode(Node $node): void
70+
{
6971
/**
7072
* adding static classes as dependencies
7173
* $constantValue = StaticClass::constant;.
@@ -83,7 +85,10 @@ public function enterNode(Node $node): void
8385
$this->classDescriptionBuilder
8486
->addDependency(new ClassDependency($node->class->toString(), $node->getLine()));
8587
}
88+
}
8689

90+
public function parseStaticClassCallsNode(Node $node): void
91+
{
8792
/**
8893
* adding static function classes as dependencies
8994
* $static = StaticClass::foo();.
@@ -101,6 +106,17 @@ public function enterNode(Node $node): void
101106
$this->classDescriptionBuilder
102107
->addDependency(new ClassDependency($node->class->toString(), $node->getLine()));
103108
}
109+
}
110+
111+
public function enterNode(Node $node): void
112+
{
113+
$this->parseClassNode($node);
114+
115+
$this->parseEnumNode($node);
116+
117+
$this->parseStaticClassConstantNode($node);
118+
119+
$this->parseStaticClassCallsNode($node);
104120

105121
if (
106122
$node instanceof Node\Expr\Instanceof_

0 commit comments

Comments
 (0)