Skip to content

Commit e172b7e

Browse files
committed
Fix FileVisitor issues with wrong class detection
It seems the php parser is using phpdocs and deciding that something like /** * @return array<int, string|int> */ is a class with FQCN `My\Namespace\array<int, string|int>` which then ofc fails to create a FullyQualifiedClassName.
1 parent 89bfe5f commit e172b7e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Analyzer/FileVisitor.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ private function handleTypedProperty(Node $node): void
228228
return;
229229
}
230230

231+
if (!class_exists($type->toString())) {
232+
return;
233+
}
234+
231235
try {
232236
$this->classDescriptionBuilder
233237
->addDependency(new ClassDependency($type->toString(), $node->getLine()));
@@ -288,7 +292,7 @@ private function handleReturnTypeDependency(Node $node): void
288292
{
289293
if ($node instanceof Node\Stmt\ClassMethod) {
290294
$returnType = $node->returnType;
291-
if ($returnType instanceof Node\Name\FullyQualified) {
295+
if ($returnType instanceof Node\Name\FullyQualified && class_exists($returnType->toString())) {
292296
$this->classDescriptionBuilder
293297
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
294298
}
@@ -300,9 +304,9 @@ private function handleAttributeNode(Node $node): void
300304
if ($node instanceof Node\Attribute) {
301305
$nodeName = $node->name;
302306

303-
if ($nodeName instanceof Node\Name\FullyQualified) {
307+
if ($nodeName instanceof Node\Name\FullyQualified && class_exists($nodeName->toString())) {
304308
$this->classDescriptionBuilder
305-
->addAttribute($node->name->toString(), $node->getLine());
309+
->addAttribute($nodeName->toString(), $node->getLine());
306310
}
307311
}
308312
}
@@ -337,6 +341,10 @@ private function addParamDependency(Node\Param $node): void
337341
return;
338342
}
339343

344+
if (!class_exists($type->toString())) {
345+
return;
346+
}
347+
340348
$this->classDescriptionBuilder
341349
->addDependency(new ClassDependency($type->toString(), $node->getLine()));
342350
}

0 commit comments

Comments
 (0)