Skip to content

Commit ca6315c

Browse files
Excludes built-in types from dependencies
Prevents built-in PHP types from being incorrectly identified as dependencies. This change improves the accuracy of dependency analysis by filtering out types like `string`, `int`, `array`, etc., ensuring that only actual project dependencies are included in the results.
1 parent 4aee07b commit ca6315c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/Infrastructure/Analyze/Adapters/PhpParser/DependencyCollectorVisitor.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public function enterNode(Node $node): void
3333
}
3434

3535
if ($node instanceof Node\Name) {
36-
$this->dependencies[] = $node->toString();
36+
$name = $node->toString();
37+
if (! $this->isBuiltinType($name)) {
38+
$this->dependencies[] = $name;
39+
}
3740
}
3841

3942
if ($node instanceof Node\Attribute) {
@@ -50,4 +53,13 @@ public function analysis(): AstClassAnalysis
5053
isAbstract: $this->isAbstract,
5154
);
5255
}
56+
57+
private function isBuiltinType(string $name): bool
58+
{
59+
return in_array(strtolower($name), [
60+
'string', 'int', 'float', 'bool', 'array', 'callable',
61+
'iterable', 'object', 'mixed', 'null', 'false', 'true',
62+
'never', 'void', 'self', 'parent', 'static',
63+
], true);
64+
}
5365
}

0 commit comments

Comments
 (0)